Warning: Creating default object from empty value in /www/htdocs/harmless/hscs.php on line 239
harmless Cocoa: AMSerialPort
AMSerialPort 2007-03-16 00:31:19
A collection of classes to access serial ports.
von sunil

I am using USB GlobalSat(USG-MR350) GPS device. I want to get location data (latitude and longitude) from the device within my mac cocoa application.Tried to run the AMSerialPort sample code.It is detecting the usb device but it is giving output in nonreadable format.How can this data be converted to readable format.

von Paul Bruneau

Thank you for your great tool!

I have had no luck in getting hardware flow control to work (maybe a limitation of my Keyspan 19HS) but in trying to solve that, I think I found some bugs in your hardware flow control getters. For example:

- (BOOL)DSROutputFlowControl
{
return (options->c_cflag & CDSR_OFLOW);
}

The result of (options->c_cflag & CDSR_OFLOW) will be 0x00080000 (CDSR_OFLOW) if that mode is set.

However, when that gets returned, it always comes back NO (I assume that the non-zero bit is too high for the CHAR type that BOOLs are).

The fix is to make the line like:
return (options->c_cflag & CDSR_OFLOW) != 0;

This should be repeated for all the similar getters.

Thanks again

von Adam Paul N/A

Excellent Serial library.

Bug addressed by Bill Myers still exists. Method readDataInBackgroundThread() of class AMSerialPortAdditions needs to ensure bytesRead is nonnegative.

MacBook Pro w/ Mac OSX 10.7.3

von Andreas www.harmless.de

Hello Sebastian

When writing that sequence of characters into a code file as a c string, the compiler will interpret it as a series of hex values and control characters and will turn it into a stream of raw bytes.

The sample application does not do that. It will only accept text input and send it as is.

von Sebastian Bach

Dear Andreas:

Thank you for your great work.

I have downloaded the AMSerialPort source and the sample.
Now I am working with a RS232 device which have a light and is allowed user to send commands to turn it on/off.

I tried input my command in the textfield in the sample as the following format.

0xAA\r0xBB\r0xCC\r0xDD\r0xEE\0

but it won't work anyway.

However if I use the "write" command with a unsigned char array assigned the above hex command, and I can turn the light on.

is there something wrong with my input format, if could, please advice me, thank you so much. any reply will be highly appreciated.

von Andreas www.harmless.de

Regarding USB-serial adapters. I can confirm that Keyspan products work.
Keyspan was recently bought by Tripp Lite. I hope the acquisition will not affect quality for the worse.

http://www.tripplite.com/en/lp/keyspan/

von chiemi

Wish I could get this to work!

When I run it, it always hangs on opening the serial port. I have a couple of USB-serial cables that are PL2303 based, and another that is Moschip based. I've tried on Leopard and Snow Leopard, PPC and Intel. Same results. Is there a list of verified cables that are known to work?

Thanks!
chiemi

von Tom

I'm trying to find my way around in the sample code...

Where does it set baud rate, parity etc.? I just can't seem to find it. :-(

von Andreas www.harmless.de

No, I haven't experimented with IOSSIOSPEED any further. Some results that turn up using a Google search seem to indicate that
1) it does work starting from 10.4 onward
2) the actual device driver still has to support the requested baud rate
3) you can't use cfgetispeed or cfgetospeed to get at the speed set with IOSSIOSPEED

von Hans S

Hello Andreas;

Thank you for your hard coding work. Have you ever successfully used the "IOSSIOSPEED" call that you have commented out? I am having trouble using this call, but need to establish communication at 921600 baud...

Thanks again!

Hans

von Thorsten Karrer hci.rwth-aachen.de/karrer

Hi,

same problem still as Craig and Jon Steinmetz. Unfortunately, it didn't occur to me to look here for a solution, so I wasted three hours to find the fix out by myself.
It would be nice if you switched the order of the remove and add calls to the arrays. Otherwise, thank you so much for the code! It's exactly what I needed to finally throw out that horrible chunk of C code that I used for the serial communication. :)

Cheers, Thorsten

von Erik

Hi!

I am trying to interface a hardware gizmo with my Mac that uses the RTS pin for not for flow control but for application specific signalling. My objective C skills are still in early development, and I cannot determine wether the IOkit serial interface provides a ioctl(MACRO_TO_SET_RTS) equivalent. Ideally I would like to implement such a method in AMSerialController.

Anyone who knows?

Cheers,
/Erik

von Craig

Hi, I've come across the same problem as Jon Steinmetz below with the same findings. In 10.4 the retain counts are 1 higher. Actually, the retain count is one lower in 10.5 under the condition of clicking anywhere on the form from the example while the device is plugged in, then unplugging the device. Jon's fix should do the trick, but I'm extremely curious as to what's going on under the hood just from clicking on the form that affects the retain count of the port object.

Seems crazy.

Thanks for the code and the great work you've all done.

-Craig

von Ronan

Hi,
i found the problem was the USB to Serial converter.
i changed from a Prolific to a FTDI chip and it works fine now.
thanks

von Andreas www.harmless.de

Hi Ronan,

> Any idea why it could consumes so much CPU ?

Not without seeing any code, no.

von Ronan

Hi,
i'm using AMSerialPort to read data from a serial device that constantly send sensors infos and noticed that when connected to the port , the application CPU load get very high ( even if i comment out all the data processing )
Any idea why it could consumes so much CPU ?
thanks !

von Rui

Im using your classes in a project, and it rocks... Thanks alot!

von Andreas www.harmless.de

James,

you probably forgot to add the IOKit.framework to your project.

See:

http://developer.apple.com/documentation/DeveloperTools/Conceptual/XcodeUserGuide/Contents/Resources/en.lproj/01_40_tasks_add_files/chapter_7_section_5.html

von James

I am looking to replace a serial port framework that I am using in my current application. The one I am using now is just not adequate for my application.

When I try to compile in a new project in leopard 10.5.2 I get some linking errors that I cannot seem to get around. The demo application compiles without any problems.

The linking problems seem to have to do with the following:

_IONotificationPortGetRunLoopSource referenced from
[AMSerialPortList registerForSerialPortChangeNotifications]

etc.. they all seem to do with _IO linking..

What am I missing?

von Timothy Reaves

Also, I noticed the included test UI also crashes when the USB plug is removed. I see from another comment that the event should be caught and cleaned up. What does that entail? (no Doxygen commands in files for documentation...)

von Timothy Reaves

Thanks for the code. Great job! Any thoughts on turning it into a framework? that's make it a little easier to use perhaps.

von Jon Steinmetz

Hi, thanks for the useful code. I have found a bug while running to code under 10.5.1. In AMSerialPortList.m near line 198 there are the lines:

[portList removeObject:serialPort];
[removedPorts addObject:serialPort];

I have found that when addObject is called the object has been released. I am not running with garbage collection but I am using Obj C 2.0. Anyway reversing the two lines:

[removedPorts addObject:serialPort];
[portList removeObject:serialPort];

Seems to fix the issue. If there is a better way to report bugs please let me know. Thanks.

von Andreas www.harmless.de

Thanks to Sean, there will be a Leopard compatible version shortly.

von Ezra electro.easyb.ch

Always worked for me so far. Having Problems with linking on Leopard though. Didn't have the time yet to give it a better look... Having more important problems with a UNIX tool that uses the serial port too. Did Apple change something?

Cheers,
Ezra.

von Andreas www.harmless.de

Previous versions had no means to detect the addition or removal of ports. So the crashes were not so much a bug as a missing feature. :)

The latest version (2007-07-31) should fix your problems. You will most likely still have to receive the appropriate notification and clean up things on your end.

Hope that helps

Andreas

von Jorge Carreira

I'm using your classes in a project to monitor (debug) a serial connection. I'm using two serial ports and I'm forwarding the data received in one port to the other port. Without your classes I would not even tried to dig into Apple API. Nice wrapper!

Thanks!
Jorge Carreira

von thefool

nice work, I'm currently using AMSerialPort in developing a small program which monitors my UMTS modem. works extremely well, except that it crashes when you unplug the usb cable and thus remove the serial port from under its nose.

I've checked with the provided AMSerialTest application, and the same thing happens, so there seems to be some bug in your classes.

the problem probably arises with any usb-serial cable, so I'd be glad if you could try it out, and contact me if you have a solution... (I'm a total newbie to cocoa, so I couldn't work out what the problem is... - I think it's somewhere in the background reading part)

thanks

theFool

Name:  Passwort: (1)
Email: (2)
Webseite: (3)
Kommentar:
{captcha}
Obige Zeichen eingeben: (Groß-/Kleinschreibung egal)
   

1) Bitte geben Sie möglichst Ihren echten Namen an. (Momentan gibt es keine Möglichkeit, einen festen Account anzulegen.)

2) Ihre Email-Adresse wird nie veröffentlicht werden. Die Angabe ermöglicht mir, Sie ggf. zu kontaktieren.

3) Die Adresse Ihrer Webseite wird zusammen mit Ihrem Namen veröffentlicht. Bitte kurz halten.

Ich behalte mir das Recht vor, Beiträge aus beliebigen Gründen zu löschen.
Also bitte keinen SPAM posten, beim Thema bleiben, nicht unverschämt werden, etc.