ScannerSettingViewController.m 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846
  1. //
  2. // ViewController.m
  3. // Test_scan
  4. //
  5. // Created by Ray on 12/22/15.
  6. // Copyright © 2015 United Software Applications, Inc. All rights reserved.
  7. //
  8. //#define USE_SOFTSCAN 1
  9. #import "ScannerSettingViewController.h"
  10. #import "AppDelegate.h"
  11. @interface ScannerSettingViewController ()
  12. @end
  13. @implementation ScannerSettingViewController
  14. {
  15. #ifdef USE_SOFTSCAN
  16. DeviceInfo* _softScanDeviceInfo;
  17. #endif
  18. DeviceInfo* _deviceInfoToTrigger;
  19. // DeviceInfo* _deviceInfoToTrigger;
  20. // NSDate* _lastCheck;
  21. // NSInteger _sameSecondCount;
  22. }
  23. //@synthesize flipsidePopoverController = _flipsidePopoverController;
  24. @synthesize Entry = _Entry;
  25. @synthesize Status = _Status;
  26. //@synthesize ScanApi;
  27. //@synthesize ScanApiConsumer;
  28. //@synthesize scanApiVersion;
  29. #pragma mark - View lifecycle
  30. - (void)onCloseClick:(UIButton *)sender {
  31. if(self.onDismissVC)
  32. self.onDismissVC();
  33. [self dismissViewControllerAnimated:true completion:nil];
  34. }
  35. - (void)viewDidLoad {
  36. [super viewDidLoad];
  37. self.support_scanner = true;
  38. self.edgesForExtendedLayout = UIRectEdgeNone ;
  39. UIBarButtonItem *closeButton = [[UIBarButtonItem alloc] initWithImage:[[UIImage imageNamed:@"close"] imageWithRenderingMode:UIImageRenderingModeAutomatic]
  40. style:UIBarButtonItemStylePlain
  41. target:self
  42. action:@selector( onCloseClick:)];
  43. self.navigationItem.rightBarButtonItem = closeButton;
  44. // NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
  45. // // CFShow(infoDictionary);
  46. // // app名称
  47. // NSString *app_Name = [infoDictionary objectForKey:@"CFBundleName"];
  48. // // app版本
  49. // NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
  50. // // app build版本
  51. // NSString *app_build = [infoDictionary objectForKey:@"CFBundleVersion"];
  52. //
  53. //
  54. // NSString* appinfo =[NSString stringWithFormat:@"App info: %@ %@ build%@",app_Name,app_Version,app_build];
  55. // self.appinfoLabel.text = appinfo;
  56. self.tv_info.layer.borderWidth=1 ; //边框粗细
  57. self.tv_info.layer.borderColor=[UIColor darkGrayColor].CGColor; //边框颜色
  58. UIApplication * app = [UIApplication sharedApplication];
  59. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  60. switch (appDelegate.api_Status) {
  61. case API_START:
  62. self.scan_switch.enabled = true;
  63. self.scan_switch.on = true;
  64. break;
  65. case API_INIT:
  66. self.scan_switch.enabled = false;
  67. break;
  68. case API_STOP:
  69. self.scan_switch.enabled = true;
  70. self.scan_switch.on=false;
  71. break;
  72. case API_CLOSING:
  73. self.scan_switch.enabled = false;
  74. break;
  75. default:
  76. break;
  77. }
  78. _Status.text = appDelegate.Status_Text;
  79. self.tv_info.text = appDelegate.log;
  80. // [appDelegate enableScanner:self.scan_switch.isOn];
  81. // _devices=[[NSMutableArray alloc]init];
  82. // change this to YES if you want SingleEntry to
  83. // confirm the decoded data
  84. // _doAppDataConfirmation=NO;
  85. // if(ScanApi==nil){
  86. //#ifdef USE_SOFTSCAN
  87. // // this is useful for SoftScan to keep a handle
  88. // // that is used in the trigger button
  89. // _softScanDeviceInfo=nil;
  90. //#endif
  91. //
  92. // ScanApi=[[ScanApiHelper alloc]init];
  93. // [ScanApi setDelegate:self];
  94. // }
  95. // Do any additional setup after loading the view, typically from a nib.
  96. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  97. bool autolaunch = [defaults boolForKey:@"EnableScannerOnLaunch"] ;
  98. self.auto_launch_switch.on = autolaunch;
  99. }
  100. - (void)didReceiveMemoryWarning {
  101. [super didReceiveMemoryWarning];
  102. // Dispose of any resources that can be recreated.
  103. }
  104. //-(void)onTimer: (NSTimer*)theTimer{
  105. // if(theTimer==ScanApiConsumer){
  106. //
  107. // // [self addlog:@"ScanApi::doScanApiReceive:"];
  108. // [ScanApi doScanApiReceive];
  109. // }
  110. //}
  111. //-(void)addlog:(NSString*) newtext
  112. //{
  113. // //
  114. // UIApplication * app = [UIApplication sharedApplication];
  115. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  116. //
  117. // [appDelegate addlog:newtext];
  118. // dispatch_async(dispatch_get_main_queue(), ^{
  119. // self.tv_info.text = appDelegate.log;
  120. //
  121. // [self.tv_info scrollRangeToVisible:NSMakeRange(appDelegate.log.length-1,0)];
  122. // });
  123. //
  124. //}
  125. #pragma mark -control events
  126. //- (IBAction)onScannerClick:(id)sender {
  127. //}
  128. - (IBAction)onChangeAutolaunch:(id)sender {
  129. NSUserDefaults *defaults =[NSUserDefaults standardUserDefaults];
  130. [defaults removeObjectForKey:@"EnableScannerOnLaunch"];
  131. [defaults setBool:self.auto_launch_switch.isOn forKey:@"EnableScannerOnLaunch"];
  132. [defaults synchronize];
  133. }
  134. -(void) alert_view :(NSString*) msg title:(NSString*) title
  135. {
  136. if(title==nil)
  137. title = @"Message";
  138. if(msg.length>0)
  139. {
  140. title=[NSString stringWithFormat:@"%@\n\n%@",title,msg];
  141. }
  142. UIAlertView * alert = [[UIAlertView alloc] initWithTitle: title message:nil delegate:nil cancelButtonTitle:@"OK" otherButtonTitles:nil, nil];
  143. [alert show];
  144. }
  145. - (IBAction)onEmailClicked:(id)sender {
  146. AppDelegate *appDelegate = (AppDelegate*)[[UIApplication sharedApplication] delegate];
  147. [appDelegate test_onDecodedDataResult:@"SCANNER TEST"];
  148. return;
  149. // UIApplication * app = [UIApplication sharedApplication];
  150. // AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  151. if(appDelegate.log.length==0)
  152. {
  153. [self alert_view:nil title:@"Log is empty sending canceled."];
  154. return;
  155. }
  156. if(self.scan_switch.isOn)
  157. {
  158. [self alert_view:nil title:@"Disable scanner first."];
  159. return;
  160. }
  161. // NSString *path = NSTemporaryDirectory();
  162. // CFUUIDRef uuidObject = CFUUIDCreate(kCFAllocatorDefault);
  163. // Get the string representation of CFUUID object.
  164. NSString* filename =[[NSUUID UUID] UUIDString];
  165. // NSString *filePath = [path stringByAppendingPathComponent:filename];
  166. MFMailComposeViewController *mc = [[MFMailComposeViewController alloc] init];
  167. if(mc==nil)
  168. return;
  169. mc.mailComposeDelegate = self;
  170. [mc setSubject:@"scaner test log"];
  171. [mc setToRecipients:@[@"ray.zhang@united-cn.net",@"RedAntSupport@united-us.net"]];
  172. NSDictionary *infoDictionary = [[NSBundle mainBundle] infoDictionary];
  173. // CFShow(infoDictionary);
  174. // app名称
  175. NSString *app_Name = [infoDictionary objectForKey:@"CFBundleName"];
  176. // app版本
  177. NSString *app_Version = [infoDictionary objectForKey:@"CFBundleShortVersionString"];
  178. // app build版本
  179. NSString *app_build = [infoDictionary objectForKey:@"CFBundleVersion"];
  180. NSString* appinfo =[NSString stringWithFormat:@"App info: %@ %@ build%@",app_Name,app_Version,app_build];
  181. // if(self.mail_content==nil)
  182. // self.mail_content=@"";
  183. NSString* htmlbody = [NSString stringWithFormat:@"<p>%@</p></br>%@",@"Process description:",appinfo];
  184. [mc setMessageBody:htmlbody
  185. isHTML:YES];
  186. NSData *data = [appDelegate.log dataUsingEncoding:NSUTF8StringEncoding];//[NSData dataWithContentsOfFile:filePath];
  187. // if(self.attachment_name.length>0)
  188. // filename = self.attachment_name;
  189. [mc addAttachmentData:data mimeType:@"text/plain" fileName:filename];
  190. [self presentModalViewController:mc animated:YES];
  191. return;
  192. }
  193. //- (IBAction)onConnectClick:(id)sender {
  194. //
  195. //
  196. //}
  197. - (IBAction)onSwitchChanged:(id)sender {
  198. // [self addlog:@"onSwitchChanged:"];
  199. UIApplication * app = [UIApplication sharedApplication];
  200. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  201. [appDelegate enableScanner:self.scan_switch.isOn];
  202. // if(self.scan_switch.isOn)
  203. // {
  204. // [self addlog:@"switch on"];
  205. //
  206. //
  207. //// [ScanApi open];
  208. //// [self addlog:@"ScanApi open"];
  209. ////
  210. //// ScanApiConsumer=[NSTimer scheduledTimerWithTimeInterval:.2 target:self selector:@selector(onTimer:) userInfo:nil repeats:YES];
  211. //// [self addlog:@"ScanApiConsumer init"];
  212. //
  213. //
  214. //// [ScanApi close];
  215. //// [self addlog:@"ScanApi opent"];
  216. // }
  217. // else
  218. // {
  219. // [self addlog:@"switch off"];
  220. //
  221. //
  222. //// [ScanApiConsumer invalidate];
  223. //// ScanApiConsumer= nil;
  224. //// [self addlog:@"ScanApiConsumer invalidate"];
  225. //
  226. //
  227. //
  228. // [ScanApi close];
  229. // [self addlog:@"ScanApi close"];
  230. //
  231. //
  232. // }
  233. }
  234. - (void)mailComposeController:(MFMailComposeViewController*)controller
  235. didFinishWithResult:(MFMailComposeResult)result
  236. error:(NSError*)error {
  237. switch (result)
  238. {
  239. case MFMailComposeResultCancelled:
  240. DebugLog(@"Mail send canceled...");
  241. break;
  242. case MFMailComposeResultSaved:
  243. DebugLog(@"Mail saved...");
  244. break;
  245. case MFMailComposeResultSent:
  246. DebugLog(@"Mail sent...");
  247. break;
  248. case MFMailComposeResultFailed:
  249. DebugLog(@"Mail send errored: %@...", [error localizedDescription]);
  250. break;
  251. default:
  252. break;
  253. }
  254. [self dismissModalViewControllerAnimated:YES];
  255. }
  256. #pragma mark -UITableViewDataSource
  257. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  258. {
  259. return 1;
  260. }
  261. - (NSInteger)tableView:(UITableView *)tableView
  262. numberOfRowsInSection:(NSInteger)section
  263. {
  264. UIApplication * app = [UIApplication sharedApplication];
  265. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  266. return appDelegate.devices.count;
  267. }
  268. - (UITableViewCell *)tableView:(UITableView *)tableView
  269. cellForRowAtIndexPath:(NSIndexPath *)indexPath
  270. {
  271. NSString* CellIdentifier = @"device_cell";
  272. UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  273. UIApplication * app = [UIApplication sharedApplication];
  274. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  275. DeviceInfo* info = appDelegate.devices[indexPath.row];
  276. cell.textLabel.text = [info getName];
  277. cell.detailTextLabel.text = info.getTypeString;
  278. return cell;
  279. }
  280. #pragma mark -UITableViewDelegate
  281. //- (void)tableView:(UITableView *)tableView
  282. //didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  283. //{
  284. //
  285. // [self addlog:@"tableView didSelectRowAtIndexPath:"];
  286. //
  287. // DeviceInfo* deviceInfo = _devices[indexPath.row];
  288. //
  289. // if(_doAppDataConfirmation==YES){
  290. // // switch the comment between the 2 following lines for handling the
  291. // // data confirmation beep from the scanner (local)
  292. // // if none is set, the scanner will beep only once when SingleEntry actually
  293. // // confirm the decoded data, otherwise the scanner will beep twice, one locally,
  294. // // and one when SingleEntry will confirm the decoded data
  295. // [ScanApi postSetDecodeAction:deviceInfo DecodeAction:kSktScanLocalDecodeActionNone Target:self Response:@selector(onSetLocalDecodeAction:)];
  296. //
  297. // // [ScanApi postSetDecodeAction:deviceInfo DecodeAction:kSktScanLocalDecodeActionBeep|kSktScanLocalDecodeActionFlash|kSktScanLocalDecodeActionRumble Target:self Response:@selector(onSetLocalDecodeAction:)];
  298. // }
  299. //
  300. // // for demonstration only, let's make sure the DPM is enabled
  301. // // first interrogate the scanner to see if it's already enabled
  302. // // and in the onGetSymbologyDpm callback, if the DPM is not already set
  303. // // then we send a Symbology property to enable it.
  304. // [ScanApi postGetSymbologyInfo:deviceInfo SymbologyId:kSktScanSymbologyDirectPartMarking Target:self Response:@selector(onGetSymbologyDpm:)];
  305. //}
  306. //#pragma mark - UI Handlers
  307. //// Trigger button handler mostly use for
  308. //// trigger a SoftScan read.
  309. //// This postSetTriggerDevice will fail if the
  310. //// postSetOverlayView is not done before.
  311. //// THIS CODE CAN BE IGNORED IF SOFTSCAN IS NOT NEEDED
  312. //- (IBAction)triggerSoftScan:(id)sender {
  313. //#ifdef USE_SOFTSCAN
  314. // [ScanApi postSetTriggerDevice:_deviceInfoToTrigger Action:kSktScanTriggerStart Target:self Response:@selector(onSetTrigger:)];
  315. //#endif
  316. //}
  317. //#pragma mark - Device Info List management
  318. //-(void) updateDevicesList:(DeviceInfo*) deviceInfo Add:(BOOL)add{
  319. //
  320. // [self addlog:@"updateDevicesList:"];
  321. //
  322. // if(add==YES){
  323. // [_devices addObject:deviceInfo];
  324. // }
  325. // else{
  326. // [_devices removeObject:deviceInfo];
  327. // }
  328. //
  329. // NSMutableString* temp=[[NSMutableString alloc]init];
  330. // for (DeviceInfo* info in _devices) {
  331. // [temp appendString:[info getName]];
  332. // [temp appendString:@"\n"];
  333. // }
  334. // if(_devices.count>0)
  335. // [temp appendString:@"ready to scan"];
  336. // else
  337. // [temp appendString:@"Waiting for Scanner..."];
  338. //
  339. // _Status.text=temp ;
  340. // [self addlog:temp];
  341. // [self.dev_table reloadData];
  342. //
  343. //}
  344. //
  345. //
  346. //#pragma mark - ScanApiHelper complete delegates
  347. //// THE 2 FOLLOWING CALLBACKS ARE FOR DEMO ONLY FOR SHOWING HOW
  348. //// TO CHECK IF A SYMBOLOGY IS ALREADY ENABLED AND IF NOT IT ENABLES
  349. //// IT RIGHT THERE. THE GOAL IS TO CONFIGURE ONCE THE SCANNER WHEN IT
  350. //// CONNECTS TO THE DEVICE. IF THERE IS NO SPECIFIC NEED TO CONFIGURE
  351. //// THE SCANNER, THESE CALLBACKS CAN BE REMOVED
  352. //
  353. //// callback received when the Get Symbology Status is completed
  354. //-(void)onGetSymbologyDpm:(ISktScanObject*)scanObj{
  355. // [self addlog:@"onGetSymbologyDpm:"];
  356. //
  357. // SKTRESULT result=[[scanObj Msg]Result];
  358. // if(SKTSUCCESS(result)){
  359. // DeviceInfo* deviceInfo=[ScanApi getDeviceInfoFromScanObject:scanObj];
  360. // if(deviceInfo!=nil){
  361. // ISktScanSymbology* symbology=[[scanObj Property]Symbology];
  362. // if([symbology getStatus]==kSktScanSymbologyStatusDisable){
  363. // [ScanApi postSetSymbologyInfo:deviceInfo SymbologyId:kSktScanSymbologyDirectPartMarking Status:TRUE Target:self Response:@selector(onSetSymbology:)];
  364. // }
  365. // }
  366. // }
  367. // else{
  368. // // an error message should be displayed here
  369. // // indicating that the DPM symbology status cannot be retrieved
  370. // }
  371. //}
  372. //
  373. //// callback received when the Set Symbology Status is completed
  374. //-(void)onSetSymbology:(ISktScanObject*)scanObj{
  375. // [self addlog:@"onSetSymbology:"];
  376. //
  377. // SKTRESULT result=[[scanObj Msg]Result];
  378. // if(!SKTSUCCESS(result)){
  379. // // display an error message saying a symbology cannot be set
  380. // }
  381. //}
  382. //
  383. ///**
  384. // *
  385. // */
  386. //-(void) onSetDataConfirmationMode:(ISktScanObject*)scanObj{
  387. //
  388. // [self addlog:@"onSetDataConfirmationMode:"];
  389. // SKTRESULT result=[[scanObj Msg]Result];
  390. // if(SKTSUCCESS(result)){
  391. //
  392. // [self addlog:@"DataConfirmation Mode OK"];
  393. //
  394. // }
  395. // else{
  396. // [self addlog:[NSString stringWithFormat:@"DataConfirmation Mode Error %ld",result]];
  397. // }
  398. //}
  399. //
  400. //
  401. ///**
  402. // *
  403. // */
  404. //-(void) onDataConfirmation:(ISktScanObject*)scanObj{
  405. // [self addlog:@"onDataConfirmation:"];
  406. // SKTRESULT result=[[scanObj Msg]Result];
  407. // if(SKTSUCCESS(result)){
  408. // [self addlog:@"Data Confirmed OK"];
  409. // }
  410. // else{
  411. // [self addlog:[NSString stringWithFormat:@"Data Confirmed Error %ld",result]];
  412. // }
  413. //}
  414. //
  415. ///**
  416. // *
  417. // */
  418. //-(void) onSetLocalDecodeAction:(ISktScanObject*)scanObj{
  419. // [self addlog:@"onSetLocalDecodeAction:"];
  420. // SKTRESULT result=[[scanObj Msg]Result];
  421. // if(SKTSUCCESS(result)){
  422. // [self addlog:@"Local Decode Action OK"];
  423. // }
  424. // else{
  425. // [self addlog:[NSString stringWithFormat:@"Local Decode Action Error %ld",result]];
  426. // }
  427. //}
  428. //
  429. ///**
  430. // *
  431. // */
  432. //-(void) onGetSoftScanStatus:(ISktScanObject*)scanObj{
  433. // SKTRESULT result=[[scanObj Msg]Result];
  434. // if(SKTSUCCESS(result)){
  435. // ISktScanProperty* property=[scanObj Property];
  436. //
  437. // [self addlog:@"SoftScan status:"];
  438. // if([property getByte]==kSktScanEnableSoftScan){
  439. // [self addlog:@"SoftScan is ENABLED"];
  440. // _softScannerEnabled=TRUE;
  441. // }
  442. // else{
  443. // _softScannerEnabled=FALSE;
  444. // [self addlog:@"SoftScan is DISABLED"];
  445. // }
  446. //
  447. //
  448. // }
  449. // else{
  450. // [self addlog:[ NSString stringWithFormat:@"getting SoftScanStatus returned the error %ld",result]];
  451. // }
  452. //}
  453. //
  454. ///**
  455. // *
  456. // */
  457. //-(void) onSetSoftScanStatus:(ISktScanObject*)scanObj{
  458. // [self addlog:@"onSetSoftScanStatus:"];
  459. // SKTRESULT result=[[scanObj Msg]Result];
  460. // if(SKTSUCCESS(result)){
  461. // [self addlog:@"SoftScan set status success"];
  462. // }
  463. // else{
  464. // [self addlog:[NSString stringWithFormat:@"SoftScan set status returned the error %ld",result]];
  465. // }
  466. //}
  467. //
  468. ///**
  469. // *
  470. // */
  471. //-(void) onSetTrigger:(ISktScanObject*)scanObj{
  472. // [self addlog:@"onSetTrigger:"];
  473. // SKTRESULT result=[[scanObj Msg]Result];
  474. // if(SKTSUCCESS(result)){
  475. // [self addlog:@"Trigger set success"];
  476. // }
  477. // else{
  478. //
  479. //
  480. // [self addlog:[NSString stringWithFormat:@"Trigger set returned the error %ld",result]];
  481. // }
  482. //}
  483. //
  484. ///**
  485. // *
  486. // */
  487. //-(void) onGetScanApiVersion:(ISktScanObject*)scanObj{
  488. // [self addlog:@"onGetScanApiVersion:"];
  489. // SKTRESULT result=[[scanObj Msg]Result];
  490. // if(SKTSUCCESS(result))
  491. // {
  492. // ISktScanProperty*property=[scanObj Property];
  493. // if([property getType]==kSktScanPropTypeVersion)
  494. // {
  495. // scanApiVersion=[NSString stringWithFormat:@"%lx.%lx.%lx.%ld",
  496. // [[property Version]getMajor],
  497. // [[property Version]getMiddle],
  498. // [[property Version]getMinor],
  499. // [[property Version]getBuild]];
  500. // }
  501. // }
  502. // else{
  503. // scanApiVersion=[NSString stringWithFormat:@"Get ScanAPI version Error: %ld",result];
  504. // }
  505. //
  506. //
  507. // [self addlog:[NSString stringWithFormat:@"ver: %@",scanApiVersion]];
  508. //}
  509. //
  510. ///**
  511. // *
  512. // */
  513. //#ifdef USE_SOFTSCAN
  514. //-(void) onSetOverlayView:(ISktScanObject*)scanObj{
  515. // SKTRESULT result=[[scanObj Msg]Result];
  516. // if(SKTSUCCESS(result)){
  517. // [self addlog:@"Overlay view set success"];
  518. // }
  519. // else{
  520. // [self addlog:[NSString stringWithFormat:@"Overlay view set returned the error %ld",result]];
  521. //
  522. //
  523. // }
  524. //}
  525. //#endif
  526. ///**
  527. // * called each time a device connects to the host
  528. // * @param result contains the result of the connection
  529. // * @param newDevice contains the device information
  530. // */
  531. //-(void)onDeviceArrival:(SKTRESULT)result device:(DeviceInfo*)deviceInfo{
  532. // [self addlog:@"onDeviceArrival:"];
  533. //
  534. // [self updateDevicesList:deviceInfo Add:YES];
  535. //
  536. //
  537. //#ifdef USE_SOFTSCAN
  538. // // if the scanner is a SoftScan scanner
  539. // if([deviceInfo.getTypeString compare:@"SoftScan"]==NSOrderedSame){
  540. // // _softScannerTriggerBtn.hidden=NO;
  541. // _softScanDeviceInfo=deviceInfo;
  542. // if(_deviceInfoToTrigger==nil)
  543. // _deviceInfoToTrigger=deviceInfo;
  544. // NSMutableDictionary* overlayParameter=[[NSMutableDictionary alloc]init];
  545. // [overlayParameter setValue:self forKey:[NSString stringWithCString:kSktScanSoftScanContext encoding:NSASCIIStringEncoding]];
  546. // [ScanApi postSetOverlayView:deviceInfo OverlayView:overlayParameter Target:self Response:@selector(onSetOverlayView:)];
  547. // }
  548. // else
  549. //#endif
  550. // {
  551. // if([deviceInfo.getTypeString compare:@"CHS 8Ci Scanner"]==NSOrderedSame){
  552. //// _softScannerTriggerBtn.hidden=NO;
  553. // _deviceInfoToTrigger=deviceInfo;
  554. // }
  555. // if(_doAppDataConfirmation==YES){
  556. // // switch the comment between the 2 following lines for handling the
  557. // // data confirmation beep from the scanner (local)
  558. // // if none is set, the scanner will beep only once when SingleEntry actually
  559. // // confirm the decoded data, otherwise the scanner will beep twice, one locally,
  560. // // and one when SingleEntry will confirm the decoded data
  561. // [ScanApi postSetDecodeAction:deviceInfo DecodeAction:kSktScanLocalDecodeActionNone Target:self Response:@selector(onSetLocalDecodeAction:)];
  562. //
  563. // // [ScanApi postSetDecodeAction:deviceInfo DecodeAction:kSktScanLocalDecodeActionBeep|kSktScanLocalDecodeActionFlash|kSktScanLocalDecodeActionRumble Target:self Response:@selector(onSetLocalDecodeAction:)];
  564. // }
  565. //
  566. // // for demonstration only, let's make sure the DPM is enabled
  567. // // first interrogate the scanner to see if it's already enabled
  568. // // and in the onGetSymbologyDpm callback, if the DPM is not already set
  569. // // then we send a Symbology property to enable it.
  570. // [ScanApi postGetSymbologyInfo:deviceInfo SymbologyId:kSktScanSymbologyDirectPartMarking Target:self Response:@selector(onGetSymbologyDpm:)];
  571. // }
  572. //
  573. //
  574. //}
  575. //
  576. //
  577. ///**
  578. // * called each time a device disconnect from the host
  579. // * @param deviceRemoved contains the device information
  580. // */
  581. //-(void) onDeviceRemoval:(DeviceInfo*) deviceRemoved{
  582. //
  583. // [self addlog:@"onDeviceRemoval:"];
  584. // [self updateDevicesList:deviceRemoved Add:NO];
  585. // if(_deviceInfoToTrigger==deviceRemoved){
  586. // _deviceInfoToTrigger=nil;
  587. // }
  588. //#ifdef USE_SOFTSCAN
  589. // if(_softScanDeviceInfo==deviceRemoved){
  590. // _softScanDeviceInfo=nil;
  591. // }
  592. // if(_deviceInfoToTrigger==nil)
  593. // _deviceInfoToTrigger=_softScanDeviceInfo;
  594. //#endif
  595. // if(_deviceInfoToTrigger==nil){
  596. //// _softScannerTriggerBtn.hidden=YES;
  597. // }
  598. //}
  599. //
  600. ///**
  601. // * called each time ScanAPI is reporting an error
  602. // * @param result contains the error code
  603. // */
  604. //-(void) onError:(SKTRESULT) result{
  605. // [self addlog:@"onError:"];
  606. //
  607. // [self addlog:[NSString stringWithFormat:@"ScanAPI is reporting an error: %ld",result]];
  608. // _Status.text=[NSString stringWithFormat:@"ScanAPI is reporting an error: %ld",result];
  609. //
  610. //}
  611. //
  612. ///**
  613. // * called each time ScanAPI receives decoded data from scanner
  614. // * @param deviceInfo contains the device information from which
  615. // * the data has been decoded
  616. // * @param decodedData contains the decoded data information
  617. // */
  618. //-(void) onDecodedDataResult:(long)result device:(DeviceInfo *)device decodedData:(ISktScanDecodedData*)decodedData{
  619. //
  620. // [self addlog:@"onDecodedDataResult:"];
  621. // //-(void) onDecodedData:(DeviceInfo *)device decodedData:(ISktScanDecodedData*)decodedData{
  622. // if(SKTSUCCESS(result)){
  623. // _Entry.text=[NSString stringWithUTF8String:(const char *)[decodedData getData]];
  624. // [self addlog:[NSString stringWithUTF8String:(const char *)[decodedData getData]]];
  625. // if(_doAppDataConfirmation==YES){
  626. // [ScanApi postSetDataConfirmation:device Target:self Response:@selector(onDataConfirmation:)];
  627. // }
  628. // }
  629. //}
  630. //
  631. //
  632. //
  633. //
  634. //
  635. ///**
  636. // * called when ScanAPI initialization has been completed
  637. // * @param result contains the initialization result
  638. // */
  639. //-(void) onScanApiInitializeComplete:(SKTRESULT) result{
  640. //
  641. // [self addlog:@"onScanApiInitializeComplete:"];
  642. //
  643. // if(SKTSUCCESS(result)){
  644. // NSString* strlog =[NSString stringWithFormat:@"onScanApiInitialize SUCCESS result:%ld",result];
  645. // [self addlog:strlog];
  646. //
  647. //#ifdef USE_SOFTSCAN
  648. // // make sure we support SoftScan
  649. // [ScanApi postSetSoftScanStatus:kSktScanSoftScanSupported Target:self Response:@selector(onSetSoftScanStatus:)];
  650. //
  651. // // check if SoftScan is enabled
  652. // [ScanApi postGetSoftScanStatus:self Response:@selector(onGetSoftScanStatus:)];
  653. //#else
  654. // // disable support SoftScan (Default, not really needed if it was never activated)
  655. // [ScanApi postSetSoftScanStatus:kSktScanSoftScanNotSupported Target:self Response:@selector(onSetSoftScanStatus:)];
  656. //#endif
  657. //
  658. // // ask for ScanAPI version (not a requirement but always nice to know)
  659. // [ScanApi postGetScanApiVersion:self Response:@selector(onGetScanApiVersion:)];
  660. //
  661. // // configure ScanAPI for doing App Data confirmation,
  662. // // if TRUE then SingleEntry will confirm the decoded data
  663. // if(_doAppDataConfirmation==YES){
  664. // [ScanApi postSetConfirmationMode:kSktScanDataConfirmationModeApp Target:self Response:@selector(onSetDataConfirmationMode:)];
  665. // }
  666. //
  667. // _Status.text=@"Waiting for scanner...";
  668. // }
  669. // else{
  670. // _Status.text=[NSString stringWithFormat:@"Error initializing ScanAPI:%ld",result];
  671. // NSString* strlog =[NSString stringWithFormat:@"Error initializing ScanAPI:%ld",result];
  672. // [self addlog:strlog];
  673. // }
  674. //}
  675. //
  676. ///**
  677. // * called when ScanAPI has been terminated. This will be
  678. // * the last message received from ScanAPI
  679. // */
  680. //-(void) onScanApiTerminated{
  681. //
  682. // [self addlog:@"onScanApiTerminated:"];
  683. //
  684. //
  685. // [ScanApiConsumer invalidate];
  686. // ScanApiConsumer= nil;
  687. // [self addlog:@"ScanApiConsumer invalidate"];
  688. //
  689. // _Status.text = @"Off";
  690. //
  691. //}
  692. //
  693. ///**
  694. // * called when an error occurs during the retrieval
  695. // * of a ScanObject from ScanAPI.
  696. // * @param result contains the retrieval error code
  697. // */
  698. //-(void) onErrorRetrievingScanObject:(SKTRESULT) result{
  699. //
  700. // [self addlog:@"onErrorRetrievingScanObject:"];
  701. // [self addlog:[NSString stringWithFormat:@"Error retrieving ScanObject:%ld",result]];
  702. // _Status.text=[NSString stringWithFormat:@"Error retrieving ScanObject:%ld",result];
  703. //}
  704. //
  705. //
  706. #pragma mark - Support scanner
  707. -(void) OnUpdateDevicesList
  708. {
  709. [self.dev_table reloadData];
  710. }
  711. -(void) onDecodedData:(NSString*) value
  712. {
  713. _Entry.text= value;
  714. }
  715. -(void) onErrorInfo:(NSString*) errorInfo
  716. {
  717. }
  718. -(void) onStatusChanged:(NSString*) status
  719. {
  720. UIApplication * app = [UIApplication sharedApplication];
  721. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  722. switch (appDelegate.api_Status) {
  723. case API_START:
  724. self.scan_switch.enabled = true;
  725. self.scan_switch.on = true;
  726. break;
  727. case API_INIT:
  728. self.scan_switch.enabled = false;
  729. break;
  730. case API_STOP:
  731. self.scan_switch.enabled = true;
  732. self.scan_switch.on=false;
  733. break;
  734. case API_CLOSING:
  735. self.scan_switch.enabled = false;
  736. break;
  737. default:
  738. break;
  739. }
  740. _Status.text = status;
  741. }
  742. -(void) onLogUpdate
  743. {
  744. UIApplication * app = [UIApplication sharedApplication];
  745. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  746. dispatch_async(dispatch_get_main_queue(), ^{
  747. self.tv_info.text = appDelegate.log;
  748. [self.tv_info scrollRangeToVisible:NSMakeRange(appDelegate.log.length-1,0)];
  749. });
  750. }
  751. - (void)reRefreshView {
  752. [self.dev_table reloadData];
  753. }
  754. @end