Reputation: 41
I trying to write a command line UART loopback test. First, I used 'devs' to find the serial port: /tyCo/0. Then I opened the serial port for read/write: fd=open("/tyCo/0",2).
Since read() appears to be a blocking call, I tried to create a task to perform the read: sp(read, fd, &W, 0x10) where W=malloc(0x10).
I tried writing to fd: write(fd,"HELLO",5) but when I display the contents at &W, I get garbage.
When I list the running tasks I see the task I created for read which is "PENDING" and has priority 100. I've used taskPrioritySet() to assign it different priorities but to no avail.
I was hoping the task I created, which I'd like to block immediately on a read() call, would wake up when I execute the write().
Any ideas on how I might accomplish a command line UART loopback test?
Upvotes: 0
Views: 878
Reputation: 329
read call is blocking as you suggest, but only blocks if there is nothing to read. So you do not have to spawn a task for it, can be just called from the command line (and if it blocks due to lack of input you can break the call and restart the command line task by sending CTRL-C via a terminal)
Another point is, W is a pointer, that points to the allocated memory. No need to take the address of it (and I am not sure if VxWorks shell handles address referencing of its variables)
As a disclaimer, currently I do not have a system to test these steps below. But having done the exact thing you are trying to do, this is how it is supposed to look like.
To sum it up, this should be a MWE:
fd=open("/tyCo/0",2)
W=malloc(0x10)
write(fd,"HELLO",5)
read(fd, W, 0x10)
d W
As a side note, tyCo/0 is often the serial port that is used for the vxWorks shell communication. So make sure you are actually using the correct port name.
To verify the operations on fileDescriptors, you can ditch the serial port and open a file as a test. At least you will be certain that you can read and write to a fileDescriptor as expected.
fd=open("testFile",2)
W=malloc(0x10)
write(fd,"HELLO",5)
read(fd, W, 0x10)
d W
Upvotes: 0