ScannerSettingViewController.m 26 KB

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