[argyllcms] Re: Problem accessing HCFR probe
- From: Frédéric Mantegazza <frederic.mantegazza@xxxxxxxxxxx>
- To: argyllcms@xxxxxxxxxxxxx
- Date: Tue, 11 Sep 2007 23:32:33 +0200
On Friday 24 August 2007 08:44, Frédéric wrote:
> If I can't make it run with libusb, I'll try to patch your code to use
> the cdc-acm driver.
Ok, I made some tests, and I really can't use the HCFR probe with libusb
(don't know why, but I had a similar error, long ago, with a scanner).
So, I patched your code to use /dev/ttyACM0 instead. This seems to work,
but as I'm not familiar with C anymore (since I started to develop in
python, 5 years ago), my code is not very efficient (for example, I added
a sleep to wait for datas after sending command).
Could you have a look on my patch, and tell me how I can improve it? And
maybe point me on big problems I can encouter, has I commented some of
low-level read/write routines (icoms)...
Thanks,
--
Frédéric
http://www.gbiloba.org
--- argyll_dev_orig/spectro/hcfr.c 2007-09-10 14:11:16.000000000 +0200
+++ argyll_dev/spectro/hcfr.c 2007-09-11 23:29:51.000000000 +0200
@@ -86,13 +86,30 @@
) {
int rv, se;
- if ((se = p->icom->write_read(p->icom, in, out, bsize, '\n', 1, to)) !=
0) {
- int ec;
+ int fd;
+ fd = open("/dev/ttyACM0", O_RDWR);
+
+ in[1] = '\n';
+ se = write(fd, in, 2);
+ if (se == -1 || se == 0) {
+ printf("hcfr command: serial i/o failure on write\n");
+ return;
+ }
+ sleep(1);
+ se = read(fd, out, MAX_MES_SIZE);
+ if (se == -1 || se == 0) {
+ printf("hcfr command: serial i/o failure on read\n");
+ return;
+ }
+ close(fd);
+
+// if ((se = p->icom->write_read(p->icom, in, out, bsize, '\n', 1, to)) !=
0) {
+// int ec;
#ifdef DEBUG
- printf("hcfr fcommand: serial i/o failure on write_read
'%s'\n",icoms_fix(in));
+// printf("hcfr fcommand: serial i/o failure on write_read
'%s'\n",icoms_fix(in));
#endif
- return hcfr_interp_code((inst *)p, icoms2hcfr_err(se));
- }
+// return hcfr_interp_code((inst *)p, icoms2hcfr_err(se));
+// }
#ifdef DEBUG
printf("command '%s'",icoms_fix(in));
printf(" returned '%s', value 0x%x\n",icoms_fix(out),HCFR_OK);
@@ -115,11 +132,11 @@
if (isdeb) printf("\nhcfr: Doing break\n");
- se = p->icom->usb_control(p->icom,
- USB_ENDPOINT_OUT | USB_TYPE_CLASS |
USB_RECIP_INTERFACE,
- 0x22, 0, 0, NULL, 0, 1.0);
-
- rv = hcfr_interp_code((inst *)p, icoms2hcfr_err(se));
+// se = p->icom->usb_control(p->icom,
+// USB_ENDPOINT_OUT | USB_TYPE_CLASS |
USB_RECIP_INTERFACE,
+// 0x22, 0, 0, NULL, 0, 1.0);
+//
+// rv = hcfr_interp_code((inst *)p, icoms2hcfr_err(se));
if (isdeb) printf("Break done, ICOM err 0x%x\n",se);
p->icom->debug = isdeb;
@@ -136,13 +153,18 @@
char buf[MAX_MES_SIZE];
inst_code ev = inst_ok;
- for (c->lerr = 0;;) {
- int debug = c->debug; c->debug = 0;
- c->read(c, buf, MAX_MES_SIZE, '\000', 100000, 0.01);
- c->debug = debug;
- if (c->lerr != 0)
- break; /* Expect timeout with
nothing to read */
- }
+ int fd, se;
+ fd = open("/dev/ttyACM0", O_RDWR);
+ se = read(fd, buf, MAX_MES_SIZE);
+ close(fd);
+
+// for (c->lerr = 0;;) {
+// int debug = c->debug; c->debug = 0;
+// c->read(c, buf, MAX_MES_SIZE, '\000', 100000, 0.01);
+// c->debug = debug;
+// if (c->lerr != 0)
+// break; /* Expect timeout with
nothing to read */
+// }
c->lerr = 0;
return inst_ok;
@@ -448,22 +470,22 @@
fprintf(stderr,"hcfr: About to init coms\n");
}
- if (p->icom->is_usb_portno(p->icom, port) == instUnknown) {
- if (p->debug) fprintf(stderr,"hcfr: init_coms called to wrong
device!\n");
-
- return HCFR_UNKNOWN_MODEL;
- }
-
+// if (p->icom->is_usb_portno(p->icom, port) == instUnknown) {
+// if (p->debug) fprintf(stderr,"hcfr: init_coms called to wrong
device!\n");
+//
+// return HCFR_UNKNOWN_MODEL;
+// }
+//
if (p->debug) fprintf(stderr,"hcfr: About to init USB\n");
-
+//
/* Set config, interface, "Serial" write & read end points */
/* Note if we clear halt the interface hangs */
- p->icom->set_usb_port(p->icom, port, 1, 0x03, 0x83, usbflags);
+// p->icom->set_usb_port(p->icom, port, 1, 0x03, 0x83, usbflags);
- if ((ev = hcfr_break(p)) != inst_ok) {
- if (p->debug) fprintf(stderr,"hcfr: Error doing break\n");
- return ev;
- }
+// if ((ev = hcfr_break(p)) != inst_ok) {
+// if (p->debug) fprintf(stderr,"hcfr: Error doing break\n");
+// return ev;
+// }
p->gotcoms = 1;
return inst_ok;
- Follow-Ups:
- [argyllcms] Re: Problem accessing HCFR probe
- From: Graeme Gill
Other related posts:
- » [argyllcms] Re: Problem accessing HCFR probe
- » [argyllcms] Re: Problem accessing HCFR probe
- » [argyllcms] Re: Problem accessing HCFR probe
- » [argyllcms] Re: Problem accessing HCFR probe
- » [argyllcms] Re: Problem accessing HCFR probe
- [argyllcms] Re: Problem accessing HCFR probe
- From: Graeme Gill