ScannerSettingViewController.m 27 KB

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