Just posted some Serial Port classes at [link removed: contained malware]
Currently Win32 and Mac only (linux can probably use the Mac code, with the enumeration functions stripped out)
from the header:
[code]a typical serialport scenario may be:
{
//get a list of serial ports installed on the system, as a StringPairArray containing a friendly name and the port path
StringPairArray portlist = SerialPort::getSerialPortPaths();
if(portlist.size())
{
//open the first port on the system
SerialPort * pSP = new SerialPort(portlist.getAllValues()[0], SerialPortConfig(9600, 8, SerialPortConfig::SERIALPORT_PARITY_NONE, SerialPortConfig::STOPBITS_1, SerialPortConfig::FLOWCONTROL_NONE));
if(pSP->exists())
{
//create streams for reading/writing
SerialPortOutputStream * pOutputStream = new SerialPortOutputStream(pSP);
SerialPortInputStream * pInputStream = new SerialPortInputStream(pSP);
pOutputStream->write("hello world via serial", 22); //write some bytes
//read chars one at a time:
char c;
while(!pInputStream->isExhausted())
pInputStream->read(&c, 1);
//or, read line by line:
String s;
while(pInputStream->canReadLine())
s = pInputStream->readNextLine();
//or ask to be notified when a new line is available:
pInputStream->addChangeListener(this); //we must be a changelistener to receive notifications
pInputStream->setNotify(SerialPortInputStream::NOTIFY_ON_CHAR, '\n');
//or ask to be notified whenever any character is received
//NOTE - use with care at high baud rates!!!!
pInputStream->setNotify(SerialPortInputStream::NOTIFY_ALWAYS);
//please see class definitions for other features/functions etc
}
}
Very convenient class, many thanks to the author. There is a slight correction to get this to compile with new Juce, relating to how Threads are being done now:
Has anyone been able to use this class for byte-to-byte nonoverlapped type of communication? I’m using pretty much the suggested code in the header file of the class. SerialPortOutputStream::write and SerialPortInputStream::read functions with one byte data (under Win XP). The first write/read call seems to return the single byte I’m looking for, the second fails (input stream exhausted). I have a serial port monitor which says there’s no answer the second time. Is my setup wrong?
//open the first port on the system
SerialPort * pSP = new SerialPort("COM1", SerialPortConfig(4800, 8, SerialPortConfig::SERIALPORT_PARITY_NONE, SerialPortConfig::STOPBITS_1, SerialPortConfig::FLOWCONTROL_NONE));
if(pSP->exists())
{
//create streams for reading/writing
SerialPortOutputStream * pOutputStream = new SerialPortOutputStream(pSP);
SerialPortInputStream * pInputStream = new SerialPortInputStream(pSP);
char c = 0;
char data = CMD_READ_TXCTRVERSION;
pOutputStream->write (&data, 1);
while(!pInputStream->isExhausted())
pInputStream->read(&c, 1);
/* Do something with c ... */
data = CMD_EXECUTEREQUEST;
pOutputStream->write (&data, 1);
while(!pInputStream->isExhausted())
pInputStream->read(&c, 1);
/* Do something with c ... */
}
delete pSP;
I have just been trying to implement this class within a project on a mac but its coming up with many errors, even after fixing the reported correction relating to the Thread class. Most of the error’s are due to undeclared variables and functions.
Has anyone got this class working in more recent times?
waking up this dead thread… I revived graffiti’s code to run with Juce 2.1.1
(after wasting precious life energy trying to get BOOST to work in Xcode to get the blipzone serial driver to work!)
I’ve done a little testing (RX on OSX works) but it needs more…
I tried to make it into a module but there’s more to that than making a manifest file, and there’s no howto anywhere so I’ll leave that to someone else. As it is you can just add these three source files to your project and it’ll selectively compile for OSX or WIN.
clang: error: no such file or directory: '/Users/mlindahl/BEA/juce/FileModularizer-master/Builds/MacOSX/…/…/Source/Code/Modularizer.cpp’
clang: error: no input files
Command /Applications/Xcode.app/Contents/Developer/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang failed with exit code 1
[/code]
Thought I'd share a quick fix if anyone is out there using this code and finds it not working on Windows 10.  This code uses overlapped I/O however it doesn't properly respond to the ERROR_IO_PENDING response from ReadFile.  In the case of ERROR_IO_PENDING you do not want to keep calling ReadFile (which is what the code currently does) but you want to wait for the first ReadFile request to process and get the results with GetOverLappedResult
I've been trying to use this code in my juce application, @NatanH wrote a very clean wrapper for this in one of his open source projects. It works, however on my El Capitan computer none of the USB port serial devices are displaying, only ones which are always available.
Â
Has anyone gotten any serial IO working on El Capitan?
Depending on the chipset with USB-serial cables you might have to manually go out and find the driver and install it (which is a weird feeling in 2016). Is it appearing at all in system profiler or /dev? Mine is a TRENDnet TU-S9, which required a download of the PL-2303 drivers.
I'm running El Capitan and haven't been able to test on a previous OS.
Â
EDIT:Â
So, sent the app to a friend who is still on yosemite, they were able to see their arduino connections through the vst. Sadly, it must be something with El Capitan, which is a bit beyond me i believe. I think i'll try disabling rootless when i get a chance and see if that is doing anything funny. Otherwise, if anyone see this & has any ideas lemme know : )Â