ScannerSettingViewController.m 27 KB

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