I made a virtual com port reader program that is in c for linux and mac
(27 posts) (5 voices)-
Posted 5 years ago #
-
Hello Josheeg,
In your posts you might want to try using the blockquote and /blockquote markups (where the markups are preceded by < and followed by >) to make it easier to see where you code starts and stops.
You used "code", but I think the indentation is a little easier to see. It is also useful when you are responding to specific comments made by other.
I tried to use HTML "&" characters to show you exactly what I mean, but I did not succeed. Can anyone tell me how to do this on this forum?
Josheeg, good luck on your serial terminal project.
Thanks!
Stephen from NYC
Posted 5 years ago # -
I get this out on gtkterm when selecting /dev/ttyUSB0
as my com port it is the one for the ft2232h board0248... like it shoudl I made the maple toggle one bit of te ft2232h up its port.
shows up as characters in gtkterm but my program doen't print anything?
Posted 5 years ago # -
My program did print the correct data when info was sent from the maple just not the ftdi chip.
Posted 5 years ago # -
I am trying to set a mask to coppy the 0-255 number that is a character into a int so I can OR bits out to create the sensors data.
But it is not working...
//set something =0
//create mask unsigned short int 255 & sensor=something
//coppy to zeroed int masked character valuePosted 5 years ago # -
Cast the char as int. IE
char bazza='a';
int barry;
barry=(int)bazza;Posted 5 years ago # -
crenn - I agree with the cast, but, to be pedantic, this is slightly safer:
unsigned char fu = 'a'; int bar = (int) fu;
because, AFAIK, the compiler can assume
char
meanssigned char
.With signed char, and with the top bit of the char variable
fu
set to 1, the compiled code will sign extendfu
on assignment tobar
, to give a negative value tobar
, with the 24 upper bits set to 1.It might result in an annoying bug, e.g. trying to combine bytes like:
char fu0, fu1, fu2, fu3; // ... do stuff to get fu0 to fu3 int bar = ((int)fu3) << 24 | ((int)fu2) << 16 | ((int)fu1) << 8 | ((int)fu0);
will break if any of fu0, fu1, or fu2 contain negative 8-bit values, whereas
unsigned char fu0, fu1, fu2, fu3; // ... do stuff to get fu0 to fu3 int bar = ((int)fu3) << 24 | ((int)fu2) << 16 | ((int)fu1) << 8 | ((int)fu0);
would work.
Posted 5 years ago # -
josheeg - I am a bit confused as to which parts of the system are working, so may I ask some questions, and suggest somethings that might be easier to test? If they are already tested, that's okay, just say what the results were.
If it is all working, please ignore this post.
As I understand the electronics, there is:
1. an FT2232H connected to a host PC
2. eight ads1298 chips shifting data into an 8-bit parallel port (FIFO) on the FT2232H
3. a Maple controlling the ads1298 and FT2232H.Have you got pieces of this working? Doing subsystems aims to make things simpler so that parts of the system can be tested and proven.
Have you tried any of these approaches?
A. One ads1298 into 1 digital input pin of the Maple, and use the Maple to receive the single data stream, pack it into bytes, and use the Maple-IDE serial monitor (using e.g. .print(value, HEX)) to display the values.
B. eight ads1298 into 8 digital input pins of the Maple, and use the Maple to receive the data, pack it into bytes to represent each individual ads1298 ADC value, and use the serial monitor to display the values.
3. use the Maple to pretend to be 8 ads1298 by feeding dummy values into the FT2232H, and use your host program to get the data.I recommend going through all three steps, but maybe you have a different way to decompose the system into testable pieces.
If you have a different approach, would you explain what that is, and what the results were?Posted 5 years ago # -
Great News! For all modified from maple examples & teensy++ serial bench mark tester serial_listen.c
The maple talks to the PC in bytes so the numbers in the 8 bits effect output on the pc.
Next will be to replace the maples possition with the FT2232h and the c code should read from the ft2232h the working code will be placed on my website.https://sites.google.com/site/openloopproject/
serial.zip has all of it.
maple first ...
blockquote
unsigned char sensor=0;
int button=38;void setup() {
pinMode(button, INPUT);
}void loop() {
sensor = digitalRead(button);
if (sensor==HIGH) sensor=255;
if (sensor==LOW) sensor=0;
SerialUSB.println(sensor, BYTE);
}/blockquote
now PC ubuntu linux
blockquote
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <fcntl.h>
#include <unistd.h>
#include <termios.h>// To compile on Ubuntu:
// gcc -O3 -Wall -o serial_listen serial_listen.cint main(int argc, char **argv)
{
unsigned char buf[16384];
int port;
int i=0;
long n;
struct termios settings;if (argc < 2) {
fprintf(stderr, "Example: serial_listen /dev/ttyACM0\n");
fprintf(stderr, "Example: serial_listen /dev/cu.usbmodem12341\n");
return 1;
}// Open the serial port
port = open(argv[1], O_RDONLY);
if (port < 0) {
fprintf(stderr, "Unable to open %s\n", argv[1]);
return 1;
}// Configure the port
tcgetattr(port, &settings);
cfmakeraw(&settings);
tcsetattr(port, TCSANOW, &settings);// Read data until we get a see the end string or get an error
printf("Reading from %s\n", argv[1]);
while (1) {
n = read(port, buf, sizeof(buf));
for (i=0; i<n; ++i){
if(buf[i]==0) printf("1 hello world button up.\n ");
if(buf[i]==255) printf("128 hello world button down.\n ");
}
}return 0;
}/blockquote
Posted 5 years ago # -
I used approach 3 & nexxt will hook 1 ads1298 to the maple ... the second is still comming together. Next will be your sugjestion A there is a png diagram called layout on my cite.
Posted 5 years ago # -
Hi Josh,
Cool! Glad to hear things are working out for you. Your program in fact seems to be something like what StephenFromNYC was asking about a little while ago --
http://forums.leaflabs.com/topic.php?id=210
(provided, of course, that you spun it out into a library and compiled it as a .dll or .so as appropriate).Although, for the record, I'm with Perry that such a library is probably unnecessary vs. just statically linking your PC-side code in with the rest of your program.
Posted 5 years ago # -
Well the other way to look at it is I can just write it as a large c program and functions in .c files and header files and not mess with linking libraries.
The only other bit of code I have for what I am working on is a c file for blind source seperation. On the PC side.
On the micro side I am getting ready to talk to the ads1298 using the maple.
So I am looking at http://leaflabs.com/docs/maple/spi/
I am curious if I can use the hardware SPI functions and the two spi ports to have a loopback. That would be good for testing the communication link before sending it to the ads1298.Posted 5 years ago #
Reply
You must log in to post.