ScannerSettingViewController.m 27 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856
  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. #ifdef USE_MFI_SCANNER
  195. // [self addlog:@"onSwitchChanged:"];
  196. UIApplication * app = [UIApplication sharedApplication];
  197. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  198. [appDelegate enableScanner:self.scan_switch.isOn];
  199. #endif
  200. // if(self.scan_switch.isOn)
  201. // {
  202. // [self addlog:@"switch on"];
  203. //
  204. //
  205. //// [ScanApi open];
  206. //// [self addlog:@"ScanApi open"];
  207. ////
  208. //// ScanApiConsumer=[NSTimer scheduledTimerWithTimeInterval:.2 target:self selector:@selector(onTimer:) userInfo:nil repeats:YES];
  209. //// [self addlog:@"ScanApiConsumer init"];
  210. //
  211. //
  212. //// [ScanApi close];
  213. //// [self addlog:@"ScanApi opent"];
  214. // }
  215. // else
  216. // {
  217. // [self addlog:@"switch off"];
  218. //
  219. //
  220. //// [ScanApiConsumer invalidate];
  221. //// ScanApiConsumer= nil;
  222. //// [self addlog:@"ScanApiConsumer invalidate"];
  223. //
  224. //
  225. //
  226. // [ScanApi close];
  227. // [self addlog:@"ScanApi close"];
  228. //
  229. //
  230. // }
  231. }
  232. - (void)mailComposeController:(MFMailComposeViewController*)controller
  233. didFinishWithResult:(MFMailComposeResult)result
  234. error:(NSError*)error {
  235. switch (result)
  236. {
  237. case MFMailComposeResultCancelled:
  238. DebugLog(@"Mail send canceled...");
  239. break;
  240. case MFMailComposeResultSaved:
  241. DebugLog(@"Mail saved...");
  242. break;
  243. case MFMailComposeResultSent:
  244. DebugLog(@"Mail sent...");
  245. break;
  246. case MFMailComposeResultFailed:
  247. DebugLog(@"Mail send errored: %@...", [error localizedDescription]);
  248. break;
  249. default:
  250. break;
  251. }
  252. // [self dismissModalViewControllerAnimated:YES];
  253. [self dismissViewControllerAnimated:YES completion:nil];
  254. }
  255. #pragma mark -UITableViewDataSource
  256. - (NSInteger)numberOfSectionsInTableView:(UITableView *)tableView
  257. {
  258. return 1;
  259. }
  260. - (NSInteger)tableView:(UITableView *)tableView
  261. numberOfRowsInSection:(NSInteger)section
  262. {
  263. UIApplication * app = [UIApplication sharedApplication];
  264. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  265. return appDelegate.devices.count;
  266. }
  267. - (UITableViewCell *)tableView:(UITableView *)tableView
  268. cellForRowAtIndexPath:(NSIndexPath *)indexPath
  269. {
  270. NSString* CellIdentifier = @"device_cell";
  271. UITableViewCell * cell= [tableView dequeueReusableCellWithIdentifier:CellIdentifier forIndexPath:indexPath];
  272. #ifdef USE_MFI_SCANNER
  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. #endif
  279. // DeviceInfo* info = appDelegate.devices[indexPath.row];
  280. // cell.textLabel.text = [info getName];
  281. // cell.detailTextLabel.text = info.getTypeString;
  282. return cell;
  283. }
  284. #pragma mark -UITableViewDelegate
  285. //- (void)tableView:(UITableView *)tableView
  286. //didSelectRowAtIndexPath:(NSIndexPath *)indexPath
  287. //{
  288. //
  289. // [self addlog:@"tableView didSelectRowAtIndexPath:"];
  290. //
  291. // DeviceInfo* deviceInfo = _devices[indexPath.row];
  292. //
  293. // if(_doAppDataConfirmation==YES){
  294. // // switch the comment between the 2 following lines for handling the
  295. // // data confirmation beep from the scanner (local)
  296. // // if none is set, the scanner will beep only once when SingleEntry actually
  297. // // confirm the decoded data, otherwise the scanner will beep twice, one locally,
  298. // // and one when SingleEntry will confirm the decoded data
  299. // [ScanApi postSetDecodeAction:deviceInfo DecodeAction:kSktScanLocalDecodeActionNone Target:self Response:@selector(onSetLocalDecodeAction:)];
  300. //
  301. // // [ScanApi postSetDecodeAction:deviceInfo DecodeAction:kSktScanLocalDecodeActionBeep|kSktScanLocalDecodeActionFlash|kSktScanLocalDecodeActionRumble Target:self Response:@selector(onSetLocalDecodeAction:)];
  302. // }
  303. //
  304. // // for demonstration only, let's make sure the DPM is enabled
  305. // // first interrogate the scanner to see if it's already enabled
  306. // // and in the onGetSymbologyDpm callback, if the DPM is not already set
  307. // // then we send a Symbology property to enable it.
  308. // [ScanApi postGetSymbologyInfo:deviceInfo SymbologyId:kSktScanSymbologyDirectPartMarking Target:self Response:@selector(onGetSymbologyDpm:)];
  309. //}
  310. //#pragma mark - UI Handlers
  311. //// Trigger button handler mostly use for
  312. //// trigger a SoftScan read.
  313. //// This postSetTriggerDevice will fail if the
  314. //// postSetOverlayView is not done before.
  315. //// THIS CODE CAN BE IGNORED IF SOFTSCAN IS NOT NEEDED
  316. //- (IBAction)triggerSoftScan:(id)sender {
  317. //#ifdef USE_SOFTSCAN
  318. // [ScanApi postSetTriggerDevice:_deviceInfoToTrigger Action:kSktScanTriggerStart Target:self Response:@selector(onSetTrigger:)];
  319. //#endif
  320. //}
  321. //#pragma mark - Device Info List management
  322. //-(void) updateDevicesList:(DeviceInfo*) deviceInfo Add:(BOOL)add{
  323. //
  324. // [self addlog:@"updateDevicesList:"];
  325. //
  326. // if(add==YES){
  327. // [_devices addObject:deviceInfo];
  328. // }
  329. // else{
  330. // [_devices removeObject:deviceInfo];
  331. // }
  332. //
  333. // NSMutableString* temp=[[NSMutableString alloc]init];
  334. // for (DeviceInfo* info in _devices) {
  335. // [temp appendString:[info getName]];
  336. // [temp appendString:@"\n"];
  337. // }
  338. // if(_devices.count>0)
  339. // [temp appendString:@"ready to scan"];
  340. // else
  341. // [temp appendString:@"Waiting for Scanner..."];
  342. //
  343. // _Status.text=temp ;
  344. // [self addlog:temp];
  345. // [self.dev_table reloadData];
  346. //
  347. //}
  348. //
  349. //
  350. //#pragma mark - ScanApiHelper complete delegates
  351. //// THE 2 FOLLOWING CALLBACKS ARE FOR DEMO ONLY FOR SHOWING HOW
  352. //// TO CHECK IF A SYMBOLOGY IS ALREADY ENABLED AND IF NOT IT ENABLES
  353. //// IT RIGHT THERE. THE GOAL IS TO CONFIGURE ONCE THE SCANNER WHEN IT
  354. //// CONNECTS TO THE DEVICE. IF THERE IS NO SPECIFIC NEED TO CONFIGURE
  355. //// THE SCANNER, THESE CALLBACKS CAN BE REMOVED
  356. //
  357. //// callback received when the Get Symbology Status is completed
  358. //-(void)onGetSymbologyDpm:(ISktScanObject*)scanObj{
  359. // [self addlog:@"onGetSymbologyDpm:"];
  360. //
  361. // SKTRESULT result=[[scanObj Msg]Result];
  362. // if(SKTSUCCESS(result)){
  363. // DeviceInfo* deviceInfo=[ScanApi getDeviceInfoFromScanObject:scanObj];
  364. // if(deviceInfo!=nil){
  365. // ISktScanSymbology* symbology=[[scanObj Property]Symbology];
  366. // if([symbology getStatus]==kSktScanSymbologyStatusDisable){
  367. // [ScanApi postSetSymbologyInfo:deviceInfo SymbologyId:kSktScanSymbologyDirectPartMarking Status:TRUE Target:self Response:@selector(onSetSymbology:)];
  368. // }
  369. // }
  370. // }
  371. // else{
  372. // // an error message should be displayed here
  373. // // indicating that the DPM symbology status cannot be retrieved
  374. // }
  375. //}
  376. //
  377. //// callback received when the Set Symbology Status is completed
  378. //-(void)onSetSymbology:(ISktScanObject*)scanObj{
  379. // [self addlog:@"onSetSymbology:"];
  380. //
  381. // SKTRESULT result=[[scanObj Msg]Result];
  382. // if(!SKTSUCCESS(result)){
  383. // // display an error message saying a symbology cannot be set
  384. // }
  385. //}
  386. //
  387. ///**
  388. // *
  389. // */
  390. //-(void) onSetDataConfirmationMode:(ISktScanObject*)scanObj{
  391. //
  392. // [self addlog:@"onSetDataConfirmationMode:"];
  393. // SKTRESULT result=[[scanObj Msg]Result];
  394. // if(SKTSUCCESS(result)){
  395. //
  396. // [self addlog:@"DataConfirmation Mode OK"];
  397. //
  398. // }
  399. // else{
  400. // [self addlog:[NSString stringWithFormat:@"DataConfirmation Mode Error %ld",result]];
  401. // }
  402. //}
  403. //
  404. //
  405. ///**
  406. // *
  407. // */
  408. //-(void) onDataConfirmation:(ISktScanObject*)scanObj{
  409. // [self addlog:@"onDataConfirmation:"];
  410. // SKTRESULT result=[[scanObj Msg]Result];
  411. // if(SKTSUCCESS(result)){
  412. // [self addlog:@"Data Confirmed OK"];
  413. // }
  414. // else{
  415. // [self addlog:[NSString stringWithFormat:@"Data Confirmed Error %ld",result]];
  416. // }
  417. //}
  418. //
  419. ///**
  420. // *
  421. // */
  422. //-(void) onSetLocalDecodeAction:(ISktScanObject*)scanObj{
  423. // [self addlog:@"onSetLocalDecodeAction:"];
  424. // SKTRESULT result=[[scanObj Msg]Result];
  425. // if(SKTSUCCESS(result)){
  426. // [self addlog:@"Local Decode Action OK"];
  427. // }
  428. // else{
  429. // [self addlog:[NSString stringWithFormat:@"Local Decode Action Error %ld",result]];
  430. // }
  431. //}
  432. //
  433. ///**
  434. // *
  435. // */
  436. //-(void) onGetSoftScanStatus:(ISktScanObject*)scanObj{
  437. // SKTRESULT result=[[scanObj Msg]Result];
  438. // if(SKTSUCCESS(result)){
  439. // ISktScanProperty* property=[scanObj Property];
  440. //
  441. // [self addlog:@"SoftScan status:"];
  442. // if([property getByte]==kSktScanEnableSoftScan){
  443. // [self addlog:@"SoftScan is ENABLED"];
  444. // _softScannerEnabled=TRUE;
  445. // }
  446. // else{
  447. // _softScannerEnabled=FALSE;
  448. // [self addlog:@"SoftScan is DISABLED"];
  449. // }
  450. //
  451. //
  452. // }
  453. // else{
  454. // [self addlog:[ NSString stringWithFormat:@"getting SoftScanStatus returned the error %ld",result]];
  455. // }
  456. //}
  457. //
  458. ///**
  459. // *
  460. // */
  461. //-(void) onSetSoftScanStatus:(ISktScanObject*)scanObj{
  462. // [self addlog:@"onSetSoftScanStatus:"];
  463. // SKTRESULT result=[[scanObj Msg]Result];
  464. // if(SKTSUCCESS(result)){
  465. // [self addlog:@"SoftScan set status success"];
  466. // }
  467. // else{
  468. // [self addlog:[NSString stringWithFormat:@"SoftScan set status returned the error %ld",result]];
  469. // }
  470. //}
  471. //
  472. ///**
  473. // *
  474. // */
  475. //-(void) onSetTrigger:(ISktScanObject*)scanObj{
  476. // [self addlog:@"onSetTrigger:"];
  477. // SKTRESULT result=[[scanObj Msg]Result];
  478. // if(SKTSUCCESS(result)){
  479. // [self addlog:@"Trigger set success"];
  480. // }
  481. // else{
  482. //
  483. //
  484. // [self addlog:[NSString stringWithFormat:@"Trigger set returned the error %ld",result]];
  485. // }
  486. //}
  487. //
  488. ///**
  489. // *
  490. // */
  491. //-(void) onGetScanApiVersion:(ISktScanObject*)scanObj{
  492. // [self addlog:@"onGetScanApiVersion:"];
  493. // SKTRESULT result=[[scanObj Msg]Result];
  494. // if(SKTSUCCESS(result))
  495. // {
  496. // ISktScanProperty*property=[scanObj Property];
  497. // if([property getType]==kSktScanPropTypeVersion)
  498. // {
  499. // scanApiVersion=[NSString stringWithFormat:@"%lx.%lx.%lx.%ld",
  500. // [[property Version]getMajor],
  501. // [[property Version]getMiddle],
  502. // [[property Version]getMinor],
  503. // [[property Version]getBuild]];
  504. // }
  505. // }
  506. // else{
  507. // scanApiVersion=[NSString stringWithFormat:@"Get ScanAPI version Error: %ld",result];
  508. // }
  509. //
  510. //
  511. // [self addlog:[NSString stringWithFormat:@"ver: %@",scanApiVersion]];
  512. //}
  513. //
  514. ///**
  515. // *
  516. // */
  517. //#ifdef USE_SOFTSCAN
  518. //-(void) onSetOverlayView:(ISktScanObject*)scanObj{
  519. // SKTRESULT result=[[scanObj Msg]Result];
  520. // if(SKTSUCCESS(result)){
  521. // [self addlog:@"Overlay view set success"];
  522. // }
  523. // else{
  524. // [self addlog:[NSString stringWithFormat:@"Overlay view set returned the error %ld",result]];
  525. //
  526. //
  527. // }
  528. //}
  529. //#endif
  530. ///**
  531. // * called each time a device connects to the host
  532. // * @param result contains the result of the connection
  533. // * @param newDevice contains the device information
  534. // */
  535. //-(void)onDeviceArrival:(SKTRESULT)result device:(DeviceInfo*)deviceInfo{
  536. // [self addlog:@"onDeviceArrival:"];
  537. //
  538. // [self updateDevicesList:deviceInfo Add:YES];
  539. //
  540. //
  541. //#ifdef USE_SOFTSCAN
  542. // // if the scanner is a SoftScan scanner
  543. // if([deviceInfo.getTypeString compare:@"SoftScan"]==NSOrderedSame){
  544. // // _softScannerTriggerBtn.hidden=NO;
  545. // _softScanDeviceInfo=deviceInfo;
  546. // if(_deviceInfoToTrigger==nil)
  547. // _deviceInfoToTrigger=deviceInfo;
  548. // NSMutableDictionary* overlayParameter=[[NSMutableDictionary alloc]init];
  549. // [overlayParameter setValue:self forKey:[NSString stringWithCString:kSktScanSoftScanContext encoding:NSASCIIStringEncoding]];
  550. // [ScanApi postSetOverlayView:deviceInfo OverlayView:overlayParameter Target:self Response:@selector(onSetOverlayView:)];
  551. // }
  552. // else
  553. //#endif
  554. // {
  555. // if([deviceInfo.getTypeString compare:@"CHS 8Ci Scanner"]==NSOrderedSame){
  556. //// _softScannerTriggerBtn.hidden=NO;
  557. // _deviceInfoToTrigger=deviceInfo;
  558. // }
  559. // if(_doAppDataConfirmation==YES){
  560. // // switch the comment between the 2 following lines for handling the
  561. // // data confirmation beep from the scanner (local)
  562. // // if none is set, the scanner will beep only once when SingleEntry actually
  563. // // confirm the decoded data, otherwise the scanner will beep twice, one locally,
  564. // // and one when SingleEntry will confirm the decoded data
  565. // [ScanApi postSetDecodeAction:deviceInfo DecodeAction:kSktScanLocalDecodeActionNone Target:self Response:@selector(onSetLocalDecodeAction:)];
  566. //
  567. // // [ScanApi postSetDecodeAction:deviceInfo DecodeAction:kSktScanLocalDecodeActionBeep|kSktScanLocalDecodeActionFlash|kSktScanLocalDecodeActionRumble Target:self Response:@selector(onSetLocalDecodeAction:)];
  568. // }
  569. //
  570. // // for demonstration only, let's make sure the DPM is enabled
  571. // // first interrogate the scanner to see if it's already enabled
  572. // // and in the onGetSymbologyDpm callback, if the DPM is not already set
  573. // // then we send a Symbology property to enable it.
  574. // [ScanApi postGetSymbologyInfo:deviceInfo SymbologyId:kSktScanSymbologyDirectPartMarking Target:self Response:@selector(onGetSymbologyDpm:)];
  575. // }
  576. //
  577. //
  578. //}
  579. //
  580. //
  581. ///**
  582. // * called each time a device disconnect from the host
  583. // * @param deviceRemoved contains the device information
  584. // */
  585. //-(void) onDeviceRemoval:(DeviceInfo*) deviceRemoved{
  586. //
  587. // [self addlog:@"onDeviceRemoval:"];
  588. // [self updateDevicesList:deviceRemoved Add:NO];
  589. // if(_deviceInfoToTrigger==deviceRemoved){
  590. // _deviceInfoToTrigger=nil;
  591. // }
  592. //#ifdef USE_SOFTSCAN
  593. // if(_softScanDeviceInfo==deviceRemoved){
  594. // _softScanDeviceInfo=nil;
  595. // }
  596. // if(_deviceInfoToTrigger==nil)
  597. // _deviceInfoToTrigger=_softScanDeviceInfo;
  598. //#endif
  599. // if(_deviceInfoToTrigger==nil){
  600. //// _softScannerTriggerBtn.hidden=YES;
  601. // }
  602. //}
  603. //
  604. ///**
  605. // * called each time ScanAPI is reporting an error
  606. // * @param result contains the error code
  607. // */
  608. //-(void) onError:(SKTRESULT) result{
  609. // [self addlog:@"onError:"];
  610. //
  611. // [self addlog:[NSString stringWithFormat:@"ScanAPI is reporting an error: %ld",result]];
  612. // _Status.text=[NSString stringWithFormat:@"ScanAPI is reporting an error: %ld",result];
  613. //
  614. //}
  615. //
  616. ///**
  617. // * called each time ScanAPI receives decoded data from scanner
  618. // * @param deviceInfo contains the device information from which
  619. // * the data has been decoded
  620. // * @param decodedData contains the decoded data information
  621. // */
  622. //-(void) onDecodedDataResult:(long)result device:(DeviceInfo *)device decodedData:(ISktScanDecodedData*)decodedData{
  623. //
  624. // [self addlog:@"onDecodedDataResult:"];
  625. // //-(void) onDecodedData:(DeviceInfo *)device decodedData:(ISktScanDecodedData*)decodedData{
  626. // if(SKTSUCCESS(result)){
  627. // _Entry.text=[NSString stringWithUTF8String:(const char *)[decodedData getData]];
  628. // [self addlog:[NSString stringWithUTF8String:(const char *)[decodedData getData]]];
  629. // if(_doAppDataConfirmation==YES){
  630. // [ScanApi postSetDataConfirmation:device Target:self Response:@selector(onDataConfirmation:)];
  631. // }
  632. // }
  633. //}
  634. //
  635. //
  636. //
  637. //
  638. //
  639. ///**
  640. // * called when ScanAPI initialization has been completed
  641. // * @param result contains the initialization result
  642. // */
  643. //-(void) onScanApiInitializeComplete:(SKTRESULT) result{
  644. //
  645. // [self addlog:@"onScanApiInitializeComplete:"];
  646. //
  647. // if(SKTSUCCESS(result)){
  648. // NSString* strlog =[NSString stringWithFormat:@"onScanApiInitialize SUCCESS result:%ld",result];
  649. // [self addlog:strlog];
  650. //
  651. //#ifdef USE_SOFTSCAN
  652. // // make sure we support SoftScan
  653. // [ScanApi postSetSoftScanStatus:kSktScanSoftScanSupported Target:self Response:@selector(onSetSoftScanStatus:)];
  654. //
  655. // // check if SoftScan is enabled
  656. // [ScanApi postGetSoftScanStatus:self Response:@selector(onGetSoftScanStatus:)];
  657. //#else
  658. // // disable support SoftScan (Default, not really needed if it was never activated)
  659. // [ScanApi postSetSoftScanStatus:kSktScanSoftScanNotSupported Target:self Response:@selector(onSetSoftScanStatus:)];
  660. //#endif
  661. //
  662. // // ask for ScanAPI version (not a requirement but always nice to know)
  663. // [ScanApi postGetScanApiVersion:self Response:@selector(onGetScanApiVersion:)];
  664. //
  665. // // configure ScanAPI for doing App Data confirmation,
  666. // // if TRUE then SingleEntry will confirm the decoded data
  667. // if(_doAppDataConfirmation==YES){
  668. // [ScanApi postSetConfirmationMode:kSktScanDataConfirmationModeApp Target:self Response:@selector(onSetDataConfirmationMode:)];
  669. // }
  670. //
  671. // _Status.text=@"Waiting for scanner...";
  672. // }
  673. // else{
  674. // _Status.text=[NSString stringWithFormat:@"Error initializing ScanAPI:%ld",result];
  675. // NSString* strlog =[NSString stringWithFormat:@"Error initializing ScanAPI:%ld",result];
  676. // [self addlog:strlog];
  677. // }
  678. //}
  679. //
  680. ///**
  681. // * called when ScanAPI has been terminated. This will be
  682. // * the last message received from ScanAPI
  683. // */
  684. //-(void) onScanApiTerminated{
  685. //
  686. // [self addlog:@"onScanApiTerminated:"];
  687. //
  688. //
  689. // [ScanApiConsumer invalidate];
  690. // ScanApiConsumer= nil;
  691. // [self addlog:@"ScanApiConsumer invalidate"];
  692. //
  693. // _Status.text = @"Off";
  694. //
  695. //}
  696. //
  697. ///**
  698. // * called when an error occurs during the retrieval
  699. // * of a ScanObject from ScanAPI.
  700. // * @param result contains the retrieval error code
  701. // */
  702. //-(void) onErrorRetrievingScanObject:(SKTRESULT) result{
  703. //
  704. // [self addlog:@"onErrorRetrievingScanObject:"];
  705. // [self addlog:[NSString stringWithFormat:@"Error retrieving ScanObject:%ld",result]];
  706. // _Status.text=[NSString stringWithFormat:@"Error retrieving ScanObject:%ld",result];
  707. //}
  708. //
  709. //
  710. #pragma mark - Support scanner
  711. -(void) OnUpdateDevicesList
  712. {
  713. [self.dev_table reloadData];
  714. }
  715. -(void) onDecodedData:(NSString*) value
  716. {
  717. _Entry.text= value;
  718. }
  719. -(void) onErrorInfo:(NSString*) errorInfo
  720. {
  721. }
  722. -(void) onStatusChanged:(NSString*) status
  723. {
  724. dispatch_async(dispatch_get_main_queue(), ^{
  725. UIApplication * app = [UIApplication sharedApplication];
  726. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  727. switch (appDelegate.api_Status) {
  728. case API_START:
  729. self.scan_switch.enabled = true;
  730. self.scan_switch.on = true;
  731. break;
  732. case API_INIT:
  733. self.scan_switch.enabled = false;
  734. break;
  735. case API_STOP:
  736. self.scan_switch.enabled = true;
  737. self.scan_switch.on=false;
  738. break;
  739. case API_CLOSING:
  740. self.scan_switch.enabled = false;
  741. break;
  742. default:
  743. break;
  744. }
  745. self.Status.text = status;
  746. });
  747. }
  748. -(void) onLogUpdate
  749. {
  750. UIApplication * app = [UIApplication sharedApplication];
  751. AppDelegate *appDelegate = (AppDelegate *)[app delegate];
  752. dispatch_async(dispatch_get_main_queue(), ^{
  753. self.tv_info.text = appDelegate.log;
  754. [self.tv_info scrollRangeToVisible:NSMakeRange(appDelegate.log.length-1,0)];
  755. });
  756. }
  757. - (void)reRefreshView {
  758. [self.dev_table reloadData];
  759. }
  760. @end