ScannerSettingViewController.m 27 KB

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