C++ :: Read By Serial Communications?

Oct 18, 2014

I read correctly in MatLab some data by serial port of a device, but in C... nothing.

Code: #include <cstdlib>
#include <stdio.h>
int main(void)
{
FILE *in;
char linha[30];
while(1)
{
// Abrir porta COM de onde se ligou a placa
in = fopen( "COM8", "r" );
if( in == NULL )
{

[code].....

The message "ERRO: no consigo abrir porta COM " don't appear, so I haven't error there. I just do not see anything in the terminal.

View 3 Replies


ADVERTISEMENT

C :: Read From A File Containing Serial Of Number

Jun 2, 2014

I want to read a file who contain a serial of number like in this example : +200,-100,+400,+200,-200 and the sign is very important for the rest of the program so i should save those signed numbers in an array or a struct that i can define with a boolen variable if it's + i give it 1 else if it's - it'll be 0

I wrote a basic file's code reader but i don't think there is a solution on it

Code:
void read_file(char *fil1){
FILE *f;
int ch[500];
f=fopen(fil1,"rt");
if(f==NULL)

[Code] .....

View 1 Replies View Related

C++ :: Read Serial Port Using Libserial?

Apr 14, 2014

I am using libserial library to communicate through the serial port in c++. the linux cpu is communicating with a modem through the serial port. basically this is what i want to do

Code:
//I want:
cpu to write command_1 to modem
Wait for the answer from modem
read serial port
check if command successful (i.e modem sends OK if successful and ERROR if there is an error)

If there is an error, resend command_1

if successful then Write command_2 to modem Wait for answer read again serial port check if command is succesful (modem again sends OK if successful and ERROR if there is an error) basically, this is the code...

Code:
serial_port <<command_1 <<'
'; //send 1st command
sleep(2); //delay a while

[Code].....

View 6 Replies View Related

C :: How To Read And Write A File Using Serial Port

Dec 29, 2013

Explain me a working code to read and write a file using serial communication.and i need to store that file.I know normal file handling in C, but how it is through serial port i am not getting.

View 1 Replies View Related

C# :: Read Barcode Scanner Value From Serial Port

Jun 2, 2010

How can i read barcode scanner value from serial port?

View 5 Replies View Related

Visual C++ :: How To Read And Write On Serial Port With MFC

Feb 17, 2013

I want to read and write value on serail port to Microcontroller with MFC. The MFC have no serial port tool like in VB Professionnal edition. I try to find MFC connect serial port example but I not found. If you have good example for read and write on serial port with MFC

View 2 Replies View Related

C++ :: Libserial Library To Interact With Modem - Read Serial Port

Jun 27, 2014

I am using libserial library to interact with a modem using c++. The C++ code sends an AT command:

Code:
my_serial_stream << "AT+CSQ" << '
' ;

The modem responds with a response, either ERROR or OK, The c++ code to read the response:

Code:
while( serial_port.rdbuf()->in_avail() > 0 )
{
char next_byte;
serial_port.get(next_byte);
std::cerr << std::hex << (int)next_byte << " ";
}
std::cerr << std::endl;

I would like to handle the response such that if the response is OK, the modem sends another command and if the response is ERROR, the modem resends the first command.

View 1 Replies View Related

Visual C++ :: Serial Communication In Windows - ClearCommError Finds No Data In Read Buffer

Dec 13, 2013

I want to send data from a laptop (windows 7, processor 2.60GHz) to a desktop (windows xp, processor 3.10GHz) using serial communication (using a USB to RS232 convertor). The WriteFile function is able to send the data from the laptop (NumberOfBytesWritten is correct). But on the desktop side, ClearCommError detects no data in the read buffer.

This is the relevant code in my desktop:

while(1) {
ClearCommError(hPort,&dwErrors,&commStatus);
if (commStatus.cbInQue != 0) ReadFile(hPort,&data,1,&dwBytesRead,NULL);
Sleep(10);
}

The if condition is never satisfied. The baudrate and other parameters in the DCB struct are the same on both sides.

The same code works when I write and read in the same system by shorting the RX and TX pins in the RS232 connector.

View 2 Replies View Related

C :: USB To Serial Communication Using Language

Dec 18, 2013

I have to communicate between two laptops using USB-to-Serial adapter. I have written 2 programs one for sending and another for receiving. Programs were written in both C and C# programming languages.

Using C language: I am able to successfully communicate using C-Programs mentioned below. But the problem is speed. It takes around 1 hour(60min) for just to pass 150MB. improving the performance of this programs...I also mention some comments along with programs for self understanding.Sender File on laptop with serial port :

Code:

#include <stdio.h>
#include <bios.h>
#include <conio.h>
}

[code]....

The above 4 programs behaves as, sender send a character and receives an ack for every character. I have followed this approach, bcoz other approaches were not working fine (in the sense the complete data is not sent, the amount of data sent is not judgeable, bcoz it will different every tym). when i used this approach it worked fine.

View 6 Replies View Related

C :: Getting Input From A Serial Connection (Hyperterminal)

Mar 15, 2013

Wondering why I cannot communicate with my microcontroller dspic33 with the Hyperterminal program. In the sample test code, I also cannot use printf. They have it set up differently and I am wondering if it is possible to redirect the output of the printf, scanf functions to the port I am using?

View 3 Replies View Related

C++ :: Reading And Writing Serial Data From USB

Jan 19, 2015

I am trying to make a project using arduino to control several power surces by time, i don't want to have an lcd, that would be easyer but i don't have enought space on my project, i want to set the time and the timing for the relays via Serial

Of curse i could set it using the serial monitor on the arduino ide, but i want to make a simple program to make the pc comunicate with the arduino and make it simpler to set the time and similar stuff. How to use one of my usb ports to print and read serial data?

View 1 Replies View Related

C++ :: Inserting Hex Value And Sending It At Serial Port

Dec 17, 2013

I am trying to convert decimal value 1 to 32 to hex value and insert it at 4th pos of char array and send it as hex value at the serial port .

My issue is it is converting to decimal to hex value but when it sends, it treat the converted hex value as char and sends it equivalent hex value.

For example

if decimal =1 then its hex = 1.
so , writebuffer[3] =1

But when we send whole writebuffer through send function, it treat this 1 as char and sends its hex value as 31. how to send its hex value.

unsigned int i=0;
char hex[3];
unsigned char hexunsigned[3];
unsigned int dec;
do {
unsigned char writebuffer[8] ={0x01, 0x05, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00};

[Code] ....

The send function is

void serial::send(unsigned char data[], DWORD noOfByte) {
DWORD dwBytesWrite;
WriteFile(serialHandle, data, noOfByte, &dwBytesWrite, NULL);
}

View 2 Replies View Related

C# :: Reading Byte From Serial Ports

Jun 8, 2014

how to use this function:

ftStatus = myFtdiDevice.Read(readData, numBytesAvailable,ref numBytesRead);

to read byte from the serial port.This function is part of the DLL that came with the chip(FT2232D) I am using on my board.I want to use the function to read a byte from the serial port and then send the value to the Graphic user interface.Unfortunately I was unable to get the expected value on my GUI.If I send for instance 40,what I get on the GUI are letters instead of the number 40 or at times the GUI will not even respond.Below are my lines of code I used to read the byte from the serial port:

The following instructions are executed whenever the CHECKBOX is checked

private
void checkBox1_CheckedChanged(object sender, EventArgs e)
{
UInt32 numBytesRead = 0;

[Code].....

View 3 Replies View Related

C :: Voltage Range - Write The Value On Serial Port

Mar 6, 2015

I have a Voltage Range from -10V up to +10V, which I transform to a voltage Range 0V to 5V, with the schematic i've attached, so I can use the A/D converter of my ATMEGA32 processor.

Now I'd like to write the value of the Input Voltage (which moves in the Range of -10V to + 10V) on the serial port, but i don't know how i should calculate this factor. At the moment, I can only write the value of the A/D Converter Input on the serial, but this is only 0V to 5V...

View 2 Replies View Related

C++ :: Write Program That Do The Algorithm Of Serial Divider?

Dec 25, 2013

Write program that do the algorithm of serial divider( You can divide to number in binary form and result also in binary.

View 2 Replies View Related

C++ :: How To Send UNICODE Characters To Serial Port

Jul 17, 2013

I am trying to write data in Russian language to the serial (RS-232) port. My display device is already set to that character code page.

But output on the device is not exactly what I require.

My code snippet is like this below

CString pBuffer = L"английский"; //Russian Language
LPBYTE pByte = new BYTE[pBuffer.GetLength() + 1];
memcpy(pByte, (VOID*)LPCTSTR(pBuffer), pBuffer.GetLength());
long nBuffer=pBuffer.GetLength()+1;
DWORD dwWritten=0;
WriteFile(pHandle , pByte, nBuffer ,&dwWritten , NULL);

pHandle is a valid handle.

View 4 Replies View Related

C# :: Receive String Plus Image From Serial Port?

Sep 3, 2014

i want to read the string plus image from serialport.

sample output:
DENOMI Ver SERIAL NUMBER
100 V <<<<IMAGE>>>>
100 N <<<<IMAGE>>>>

but when im trying to receive the data and using serialPort.ReadExisting();

this is the output:

DENOMI Ver SERIAL NUMBER
100 V *!???????q??q??y??y?y?q?????????xxxxppppp????y?py?`q??q??q? q???????????????8?p8?@8??8???????? ?????8??8?p8?p?p??p??p?????????q?q?p8 p88?p8?????????????8?p8?p8?p8?p8??8??x??x8?8?8??p?p??p??p0?py?p????????~8?q??q??q??p8?????p??????????????????????????????p8?x?x<?x<?x<??<?????

View 1 Replies View Related

C# :: How To Send And Receive Data From Serial Port

Aug 13, 2014

private void button1_Click(object sender, EventArgs e) {
serialPort1.PortName = "COM1";
serialPort1.BaudRate = 9600;
serialPort1.DataBits = 8;
serialPort1.Parity = Parity.None;
serialPort1.StopBits = StopBits.One;

[Code]...

In my project i have a serialport control and a button, there is no error but i want to know how actually this works, i want to send and recieve the data from the serial port don't know how to do it..

View 9 Replies View Related

C/C++ :: How To Completely Send A String Through Serial Port

May 9, 2013

I am doing a messaging application using Visual C++ window form application.

Sometimes I can't receive a whole message from the sender. If i type short sentence like "123456", it can be shown properly. But, if i type a quite long sentence like "123456789123456789", it can't shown a correct message, can't show exactly the whole message.

here is my code:

//transmission:
String^ message;
String^ message1;
String^ name = this->serialPort1->PortName;

[Code].....

View 1 Replies View Related

Visual C++ :: Manage Serial Communication With A Pedal

Jan 17, 2013

I wrote a class pedal that allows to search for the serial port on which the pedal is connected. Therefore I send a request to the pedal and set up a timer event of 20 ms. If no reply, I search for the next serial port.

When found I send configuration to the pedal and set another timer event of 200 ms that requests for pedal state. It runs fine.

Now if the pedal is disconnected then connected again I would like it to run again.

Therefore I set another timer event every 2s that launches all what I described above.

The trouble comes because the 20 ms timer event doesn't run and I do not understand why.

View 3 Replies View Related

C :: Dragon Board Serial Monitor Programming Menu

Apr 2, 2014

I am working on my senior project and my currect task is to make a menu. I dont know what the best way to do it. my code is not complete and i am completely lost. code found below:

Code:

#include <hidef.h> /* common defines and macros */#include "derivative.h" /* derivative-specific definitions */
#include "lcd.h"
#include<menu.h>
void main(void) {
char *msg1 = "Menu";

[code].....

View 4 Replies View Related

C :: How To Capture And Store Serial Communication Data In Buffers

Jun 18, 2013

I sent 1preample and 4bytes in transmitting side , preample contains only 1 and 0 with 4milliseconds delay, each byte contains 8bits with 2milliseconds delay , if a bit contains 1 it will send 1millisecond high and 1millisecond low signal ,and if a bit contains 0 it will send 2millisecond continuous delay, I have a problem at receiving side how to capture and store the preample and 4byte values in a buffer , i am using ARM processor it will update every 5microsecond ..

View 1 Replies View Related

C# :: Receive Data From Serial Com Port In One Line And Convert To Int

Mar 8, 2014

i have problem i make code that take data from serial com port for weighting machine it is ok working but it recieve data in more lines.I try to make it receive data in one line In code below i need to take weight fro weight bridge machine automatically by timer in visual studio 2005.it works but receive weight values in more lines. I need to receive weight in one line and automatically updated then convert t to integer

void Application_Idle(object sender, EventArgs e)
{
label3.Text = serialPort1.IsOpen ? "[Open]" : "[Closed]";
}

[Code].....

View 3 Replies View Related

Visual C++ :: Data Stuck When Debugging With Serial Port

May 10, 2014

I am making a MFC application with VC++2012 with receiving data from Serial Port and the data is stored in a Listbox, then after processing (convert into numbers) and get these data to draw a sine wave on the chart. (I intend to make a virtual oscilloscope).

Everything works ok at the beginning, but after receiving about 300 items or above (in the Listbox) the value seem stucking (or lagging) and work very slowly.

I receive data by the SerialPort_DataReceived() method, and process of converting and drawing chart also in this method, I think this makes the system overload!!

View 1 Replies View Related

C Sharp :: Retrieving USB Pendrive Vendor ID / Product ID And Serial Number

Sep 15, 2012

I am trying to retrieve the parameters from externally connected pendrive. I have been using WMI to achieve this but not able to separate the pendrive's parameters from the other USB devices (such as USBcamera,USBHub etc) ....

View 2 Replies View Related

Visual C++ :: Sending Packet Of Type Byte To Serial Port

Feb 26, 2013

I need to send a packet of type byte:

0x00, 0x01, 0x02, 0x11, 0x00, 0x00

to a device via the serial port and then I receive and store data coming from device like this:

0x01, 0x01, 0x01 , 0x00, 0x00, 0x00, 0x01, 0x00, 0x04, 0x01, 0x00.

Writing lines of code through which:

1) I create the array
2) the sending the array to serial port
3) I'll see what I'm sending
4) I get the data

I'm using Visual Studio 2010 and C + + or VC++ language.

View 14 Replies View Related







Copyrights 2005-15 www.BigResource.com, All rights reserved