From lv_paulrijk at xs4all.nl Wed Oct 31 08:27:43 2012
From: lv_paulrijk at xs4all.nl (PaulRijk)
Date: Wed, 31 Oct 2012 16:27:43 +0100


Subject: [Mac]Bug in serial reading binary data
In-Reply-To: <45D52276-5233-4F5D-9C78-A0F87EB06B00@magnet.fsu.edu>
References: <0160AA0E-D5D3-4361-BCF3-E7351E9106AB@xs4all.nl>
<1D4B1405-0E61-4A52-82FB-574E14735FA9@magnet.fsu.edu>
<AC72D9FC-1881-4AF0-ABF8-AE422335C84E@xs4all.nl>
<45D52276-5233-4F5D-9C78-A0F87EB06B00@magnet.fsu.edu>
Message-ID: <C73E214A-E444-461C-AFAD-7A6FA57B9B76@xs4all.nl>

Scott,

Indeed, after UNinstalling the FTDI-driver did not see the usb-serial adapter anymore. However, I noticed the problem when communicating with an Arduino-Uno which is visible (and communicating) with or without the FTDI-driver.
So using the Arduino on the other side I was able to check both.

Thanks for sending the code. Unfortunately I don't have a compiler. Is it possible for you to mail it as an executable?

Paul.
____________________
On 31 okt. 2012, at 15:47, Scott Hannahs wrote:

> Paul,
>
> I am not sure how you can read bytes at a serial port without a driver? The drivers should unload and tear down the serial port interface when the USB is unplugged. If the Serial driver is uninstalled then either some default driver will try to take over that USB interface or it will not match a driver and nothing will be loaded.
>
> At the end of this message is a program that will report the number of bytes at a serial port every 0.1 seconds. Save the text below the line as serialcount.c. use the command "make serialcount" to compile (stupid autocorrect keeps changing the program name in the email!).
>
> The routine sets the port to raw input and 38.4kbps. The speed can be changed by editing the B38400 parameter to the obvious other values.
>
> Run this with a path to the /dev/XXXXXX device that is your serial port. Does it show the same doubling of the 0xFF character? If this program shows the doubling then it is at a lower level of the system than VISA. If not then probably VISA is the culprit. There are weird settings for escape characters in serial ports from terminal days but VISA should be passing the raw data.
>
> -Scott
>
> On Oct 31, 2012, at 9:08 AM, PaulRijk <lv_paulrijk at xs4all.nl> wrote:
>
>> I'm using an USB-COMi-M usb-serial adapter with the driver FTDIUSBSerialDriver_v2_2_18.
>> BUT, when this is UNinstalled the problem remains.
>> Regards,
>> Paul
>> ________________________
>> On 31 okt. 2012, at 13:57, Scott Hannahs wrote:
>>
>>> Wow. That is weird.
>>>
>>> What USB-Serial adaptor are you using? What driver version. That could be the problem before it even gets to VISA. I think I can whip up a C program that will show # of bytes at serial port direct from the driver.
>>>
>>> -Scott
>>>
>>> On Oct 31, 2012, at 8:36 AM, PaulRijk <lv_paulrijk at xs4all.nl> wrote:
>>>
>>>> When reading binary data the property node "Serial Settings:Number of Bytes at Serial Port" shows a wrong number of bytes when one or more bytes has the value of xFF. For each byte on the bus containing xFF the #bytes is incremented by one.
>>>> So when the bytes 10,20,30,255,112 are sent to the computer, LabVIEW's #bytes shows 6 bytes. So reading 6 bytes will time-out after which 5 bytes are received with the values as sent. When the bytes 10,20,30,254,112 were sent, everything is OK.
>>>> It should be nice if there is somebody able to try this using a different language than LabVIEW.
>>>> This was done on MacBookPro MacOsX10.7.5 and VISA5.2.0 LabVIEW2009SP1/2012
>>>> If this is reproducible it is a bug in my opinion.
>>>> Regards,
>>>> Paul
>
> ---------------------------------------------------------------------------------------------------------------
> /* serialcount.c
> serialcount [device path]
> example "serialcount /dev/cu.USA28X3d11P1.1"
> Routine to display number of characters at a serial port.
> For Mac OS X use command "make serialcount" to compile
> must have XCode installed and preferences to install commandline tools
> Routine defaults to Keyspan serial port
> sets port to raw, 38.4 kBps, comment out if you don't want
> these settings changed.
> Version 1.0 2012-10-31 Scott Hannahs <sth at info-labview.org>
> */
> #include <stdlib.h>
> #include <fcntl.h>
> #include <stdio.h>
> #include <sys/types.h>
> #include <sys/uio.h>
> #include <sys/ioctl.h>
> #include <unistd.h>
> #include <termios.h>
>
> #define TRUE 1
>
> int
> main(argc, argv)
> int argc;
> char *argv[];
> {
> char *port;
> int fd, rderr, nBytes, oldNBytes;
> struct termios term;
> long int count = 0;
>
> if (argc < 2) port = "/dev/cu.KeySerial1";
> else port = argv[1];
>
> if (-1 == (fd=open(port, O_RDWR))) {
> fprintf(stderr, "Error opening terminal \"%s\" for writing and reading\n", port);
> exit(-1);
> }
>
> if (-1 == tcgetattr(fd, &term)) {
> fprintf(stderr, "Error reading terminal \"%s\" properties\n", port);
> exit(-2);
> }
>
> // Comment out following 2 lines if you don't want to change port properties
> cfmakeraw(&term);
> cfsetspeed(&term, B38400);
> term.c_cc[VMIN] = 0;
> term.c_cc[VTIME] = 1;
>
> // Comment out following 3 lines if you don't want to change port properties
> if (-1 == tcsetattr(fd, TCSANOW, &term)) {
> fprintf(stderr, "Error setting terminal \"%s\" properties\n", port);
> exit(-1);
> }
>
> printf("starting loop\n");
> oldNBytes = -1;
> while (TRUE) {
> if (-1 == ioctl(fd, FIONREAD, &nBytes)) {
> fprintf(stderr, "Error getting number of bytes from port\n");
> fprintf(stderr, "Cycled %ld times\n", count);
> perror("Error returned by ioctl(fd, FIONREAD, &nBytes):");
> exit(-3);
> } else if (nBytes != oldNBytes) {
> printf("\rNumber of bytes at port: %4d", nBytes);
> fflush(stdout);
> oldNBytes = nBytes;
> }
> count++;
> usleep(100000);
> }
> printf("\n");
> }
> _______________________________________________
> Info-labview mailing list
> Info-labview at lists.infolabview.org
> http://lists.infolabview.org/listinfo.cgi/info-labview-infolabview.org