Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Application Programming › Send data over Serial using C
New Posts  All Forums:Forum Nav:

Send data over Serial using C

post #1 of 4
Thread Starter 
Figured it out

By adding \
to the end of the string, it sent it out.

I having trouble getting this program to work that needs to be able to send data over serial. The program compiles and runs fine but I don't get the message on the other end. When I close the program and open another peice of software that can send data over serial, my message appears as it starts up. The only thing I can figure is that the buffer is not getting flushed properly. Here is the code in question. I am new to these functions so is there some step that I am missing here?

Code:

FILE * fd;

...main and other stuff...

uint8_t SendSerial(char *data, uint32_t data_size)
{
  uint8_t retval;

  strcat(data, "\\0");
  retval = fputs(data, fd);
  retval = fflush(fd);
  fclose(fd);
  return retval;
}

Edited by FireMarshallBill - 3/19/11 at 9:54am
Fire Computer
(17 items)
 
Fire Yoga
(13 items)
 
Fire Server
(13 items)
 
CPUMotherboardGraphicsRAM
Intel Core i5-3570K Ivy Bridge 3.4GHz (3.8GHz T... GIGABYTE GA-Z77X-UD5H LGA 1155 Intel Z77 HDMI S... GTX680-DC2O-2GD5 CORSAIR DOMINATOR GT 4GB 240-Pin DDR3 SDRAM DDR... 
Hard DriveHard DriveOptical DriveCooling
Seagate Samsung Light Scribe DVD Burner H50 
OSMonitorKeyboardPower
Windows 7 Professional 64 bit ASUS VH226H 21.5" Logitech G15 Corsair 850W 
CaseMouseAudioAudio
Corsair 500R Logitech M500  HDA X-Plosion 7.1 Boston Acustics BA7500 
CPUGraphicsRAMHard Drive
Intel Core i5-3317U Intel(R) HD Graphics 4000 4GB x2 128 GB SSD 
Hard DriveOS
256GB SSD Windows 8 
  hide details  
Reply
Fire Computer
(17 items)
 
Fire Yoga
(13 items)
 
Fire Server
(13 items)
 
CPUMotherboardGraphicsRAM
Intel Core i5-3570K Ivy Bridge 3.4GHz (3.8GHz T... GIGABYTE GA-Z77X-UD5H LGA 1155 Intel Z77 HDMI S... GTX680-DC2O-2GD5 CORSAIR DOMINATOR GT 4GB 240-Pin DDR3 SDRAM DDR... 
Hard DriveHard DriveOptical DriveCooling
Seagate Samsung Light Scribe DVD Burner H50 
OSMonitorKeyboardPower
Windows 7 Professional 64 bit ASUS VH226H 21.5" Logitech G15 Corsair 850W 
CaseMouseAudioAudio
Corsair 500R Logitech M500  HDA X-Plosion 7.1 Boston Acustics BA7500 
CPUGraphicsRAMHard Drive
Intel Core i5-3317U Intel(R) HD Graphics 4000 4GB x2 128 GB SSD 
Hard DriveOS
256GB SSD Windows 8 
  hide details  
Reply
post #2 of 4
I would set the output stream as unbuffered; see the setbuf() call.
Underground
(14 items)
 
  
CPUMotherboardGraphicsRAM
Core i7 920 C0 ASUS P6T6 WS Revolution GTX 460 TR3X6G1600C8D 
Hard DriveOptical DriveCoolingOS
WD1001FALS SAMSUNG SH-S223F 22X DVD MULTI Corsair H50 Fedora 16 KDE x86_64 
MonitorKeyboardPowerCase
HP w19b Microsoft Comfort Curve Corsair CX600 Thermaltake Armor VA8003BWS 
MouseMouse Pad
Razer DeathAdder Black 
  hide details  
Reply
Underground
(14 items)
 
  
CPUMotherboardGraphicsRAM
Core i7 920 C0 ASUS P6T6 WS Revolution GTX 460 TR3X6G1600C8D 
Hard DriveOptical DriveCoolingOS
WD1001FALS SAMSUNG SH-S223F 22X DVD MULTI Corsair H50 Fedora 16 KDE x86_64 
MonitorKeyboardPowerCase
HP w19b Microsoft Comfort Curve Corsair CX600 Thermaltake Armor VA8003BWS 
MouseMouse Pad
Razer DeathAdder Black 
  hide details  
Reply
post #3 of 4
Thread Starter 
Quote:
Originally Posted by error10 View Post
I would set the output stream as unbuffered; see the setbuf() call.
Same thing happens, nothing is sent then when I open minicom, the message appears.
Fire Computer
(17 items)
 
Fire Yoga
(13 items)
 
Fire Server
(13 items)
 
CPUMotherboardGraphicsRAM
Intel Core i5-3570K Ivy Bridge 3.4GHz (3.8GHz T... GIGABYTE GA-Z77X-UD5H LGA 1155 Intel Z77 HDMI S... GTX680-DC2O-2GD5 CORSAIR DOMINATOR GT 4GB 240-Pin DDR3 SDRAM DDR... 
Hard DriveHard DriveOptical DriveCooling
Seagate Samsung Light Scribe DVD Burner H50 
OSMonitorKeyboardPower
Windows 7 Professional 64 bit ASUS VH226H 21.5" Logitech G15 Corsair 850W 
CaseMouseAudioAudio
Corsair 500R Logitech M500  HDA X-Plosion 7.1 Boston Acustics BA7500 
CPUGraphicsRAMHard Drive
Intel Core i5-3317U Intel(R) HD Graphics 4000 4GB x2 128 GB SSD 
Hard DriveOS
256GB SSD Windows 8 
  hide details  
Reply
Fire Computer
(17 items)
 
Fire Yoga
(13 items)
 
Fire Server
(13 items)
 
CPUMotherboardGraphicsRAM
Intel Core i5-3570K Ivy Bridge 3.4GHz (3.8GHz T... GIGABYTE GA-Z77X-UD5H LGA 1155 Intel Z77 HDMI S... GTX680-DC2O-2GD5 CORSAIR DOMINATOR GT 4GB 240-Pin DDR3 SDRAM DDR... 
Hard DriveHard DriveOptical DriveCooling
Seagate Samsung Light Scribe DVD Burner H50 
OSMonitorKeyboardPower
Windows 7 Professional 64 bit ASUS VH226H 21.5" Logitech G15 Corsair 850W 
CaseMouseAudioAudio
Corsair 500R Logitech M500  HDA X-Plosion 7.1 Boston Acustics BA7500 
CPUGraphicsRAMHard Drive
Intel Core i5-3317U Intel(R) HD Graphics 4000 4GB x2 128 GB SSD 
Hard DriveOS
256GB SSD Windows 8 
  hide details  
Reply
post #4 of 4
You need to post the rest of your code.
Underground
(14 items)
 
  
CPUMotherboardGraphicsRAM
Core i7 920 C0 ASUS P6T6 WS Revolution GTX 460 TR3X6G1600C8D 
Hard DriveOptical DriveCoolingOS
WD1001FALS SAMSUNG SH-S223F 22X DVD MULTI Corsair H50 Fedora 16 KDE x86_64 
MonitorKeyboardPowerCase
HP w19b Microsoft Comfort Curve Corsair CX600 Thermaltake Armor VA8003BWS 
MouseMouse Pad
Razer DeathAdder Black 
  hide details  
Reply
Underground
(14 items)
 
  
CPUMotherboardGraphicsRAM
Core i7 920 C0 ASUS P6T6 WS Revolution GTX 460 TR3X6G1600C8D 
Hard DriveOptical DriveCoolingOS
WD1001FALS SAMSUNG SH-S223F 22X DVD MULTI Corsair H50 Fedora 16 KDE x86_64 
MonitorKeyboardPowerCase
HP w19b Microsoft Comfort Curve Corsair CX600 Thermaltake Armor VA8003BWS 
MouseMouse Pad
Razer DeathAdder Black 
  hide details  
Reply
New Posts  All Forums:Forum Nav:
  Return Home
  Back to Forum: Application Programming
Overclock.net › Forums › Software, Programming and Coding › Coding and Programming › Application Programming › Send data over Serial using C