Odd Return Codes (fe, fc)

Interested in integrating USB-UIRT support into an application? Look here!

Moderator: jrhees

Odd Return Codes (fe, fc)

Postby MrFlick » Tue Aug 22, 2006 9:24 pm

I'm writing a program to connect to the device with my Mac. I seem to be receiving signals ok, but i'm having a problem sending simple commands. When i try to set the mode to raw (by sending {0x21, 0xfd}) i get a response of 0xfcfe. Subsequent received signals are still 6 bytes and not the raw format. Any idea what this return code might be? I also get errors with other commands i've tried (setting mode to UIR, getting version info). These don't seem to match the response codes listed in the documentation.

BTW, i'm using the FTDI driver to communicate with the device as if it were on a serial port as i saw recommended on another thread. Is this still the suggested method for connectivity on a Mac?
MrFlick
 
Posts: 3
Joined: Tue Aug 22, 2006 9:12 pm
Location: Grand Rapids, MI, USA

Postby judapeno » Thu Aug 24, 2006 12:44 am

You aren't calculating the checksum correctly. The command should be 0x21df. I would expect a "bad checksum" response. Maybe you aren't reading the response correctly? I'll look at your routine if you post it.

David
judapeno
 
Posts: 6
Joined: Mon Jan 16, 2006 6:40 am

My Typo

Postby MrFlick » Thu Aug 24, 2006 12:56 am

Oops, i typed it wrong in my post. I am using the x21df in my code. Here's a clip of what i'm doing...

Code: Select all
unsigned char   msgBuf[2] = {0x21, 0xdf};
NSData *commandMessage = [[NSData alloc ] initWithBytes:msgBuf length:2];
[deviceHandle writeData: commandMessage];
[commandMessage release];


It's all done in Cocoa. deviceHandle is an NSFileHandle object. The NSFileHandle has been sent the readInBackgroundAndNotify message to get data as it arrives. That code looks like

Code: Select all
NSData *data = [[note userInfo] valueForKey:NSFileHandleNotificationDataItem];
if(data)
   NSLog(@"data received (%d): %@", [data length], [data description]);
[deviceHandle readInBackgroundAndNotify];
MrFlick
 
Posts: 3
Joined: Tue Aug 22, 2006 9:12 pm
Location: Grand Rapids, MI, USA

Postby judapeno » Thu Aug 24, 2006 2:02 am

I don't know Cocoa, but if you can compile POSIX C code, this should work. I don't configure the baudrate, because it's automatically set to 312500 on Linux. You will also probably need to change the device filename. What is it on the Mac?

Code: Select all
#include <stdio.h>   /* Standard input/output definitions */
#include <string.h>  /* String function definitions */
#include <unistd.h>
#include <fcntl.h>   /* File control definitions */
#include <errno.h>   /* Error number definitions */
#include <termios.h> /* POSIX terminal control definitions */
#include <sys/ioctl.h>

main ()
{
int fd;
int status;

fd = open("/dev/usb-uirt", O_RDWR | O_NOCTTY | O_NDELAY);
if (fd == -1)
{
   perror("open_port");
   return;
}

char ir[] = {0x21,0xdf};
char r[5];
int w;
w = write(fd, ir, sizeof(ir));
printf("sent command, write returned %d.\n", w);
sleep(1);
w = read(fd, r, 1);
if (w == 1)
{
   printf("usb-uirt returned 0x%x.\n", r[0]);
}
else
{
   printf("tried to read one byte, read returned %d.\n", w);
}

close(fd);
}
judapeno
 
Posts: 6
Joined: Mon Jan 16, 2006 6:40 am

Bad baud rate

Postby MrFlick » Thu Aug 24, 2006 2:52 am

I'm glad you listed the baud rate in the reply. For some reason the Word document i have, "USB-UIRT Command Protocol," had a baud rate of 125,000 listed. Switching over to 312500 seemed to do the trick. To set the baud rate i used:

Code: Select all
speed_t speed = 312500;
ioctl(fd, IOSSIOSPEED, &speed);


Which, according to the Apple SerialPortSample application, is only available starting at OS 10.4. Apparently you can't use "non-standard" baud rates with earlier versions of the OS (which really isn't a problem for me, but i thought i would share for compleness).

If you have a different version of the developer documentation, can you send it to me?
MrFlick
 
Posts: 3
Joined: Tue Aug 22, 2006 9:12 pm
Location: Grand Rapids, MI, USA

Postby judapeno » Thu Aug 24, 2006 3:32 am

I suspected the baudrate could be a problem. I don't think the protocol doc has been updated, but most of the changes are here:

http://www.usbuirt.com/phpBB2/viewtopic.php?t=25

Go down a couple screens to a post from Jon. You should also know that recently purchased usb-uirt's require that you set DTR low in order for the internal emitter to work.

David
judapeno
 
Posts: 6
Joined: Mon Jan 16, 2006 6:40 am


Return to Developers

Who is online

Users browsing this forum: No registered users and 22 guests

cron