ScannerSettingViewController.m 27 KB

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