disculpa que te envié este otro link sobre el manual es casi igual al anterior solo que este me parece que algunas cosas en la sección de comunicación presenta mejor la información http://www.vestildocs.com/manuals/scale-s_1209.pdf saludos
Esta sección te permite ver todos los mensajes escritos por este usuario. Ten en cuenta que sólo puedes ver los mensajes escritos en zonas a las que tienes acceso en este momento.
Mostrar Mensajes MenúC°xxCx° Cx°Cx xxx° xCx x°xC C C C C C C C°xxCx°
es el que se repite constantemente cuando la bascula esta indicando el valor 0 kg absolutamente todos esos codigos, sin mover nada simplemente la bascula de mantiene en 0, porque lo digo, porque cuando cambia el valor por ejemplo 200 kg se representan otros símbolos que no poseo en este momento. Cuando vuelve a 0 kg vuelve a indicar el valor C°xxCx° Cx°Cx xxx° xCx x°xC C C C C C C C°xxCx°
completo es un patron que se repite constantemente claro siempre y cuando este en 0 kg cuando cambia a otro peso cambian los codigos.
#ifndef serie_h
#define serie_h
#include <windows.h>
// Open Serial port
HANDLE OpenSerialPort( char *psPort, // "COM1","COM2"
DWORD bBaudRate, // CBR_9600, CBR_19200. CBR_56000
BYTE bByteSize, // 7,8
BYTE bParity, // NOPARITY, EVENPARITY, ODDPARITY
BYTE bStopBits, // ONESTOPBIT, ONE5STOPBITS, TWOSTOPBITS
DWORD ReadTimeout // Programmable Read Timeout
);
// Send a byte
BOOL SerialSendByte(HANDLE hPort, BYTE byte);
// return TRUE: Send OK
// Receive a byte
BOOL SerialReceiveByte(HANDLE hPort, BYTE *pbyte, BOOL *pTimeout);
// return TRUE & *pTimeout TRUE Send OK
// return TRUE & *pTimeout FALSE Timeout
// return FALSE Receive Error
// Close Serial Port
BOOL CloseSerialPort(HANDLE hPort);
// Write&Read strings from serial port using standard file I/O functions
/*BOOL ReadFile(
HANDLE hFile, // handle of file or serial port to read
LPVOID lpBuffer, // address of buffer that receives data
DWORD nNumberOfBytesToRead, // number of bytes to read
LPDWORD lpNumberOfBytesRead, // address of number of bytes read
LPOVERLAPPED lpOverlapped // NULL
);
*/
/*
BOOL WriteFile(
HANDLE hFile, // handle to file or serial port to write to
LPCVOID lpBuffer, // pointer to data to write to file
DWORD nNumberOfBytesToWrite, // number of bytes to write
LPDWORD lpNumberOfBytesWritten, // pointer to number of bytes written
LPOVERLAPPED lpOverlapped // NULL
);
*/
#endif
///Archivo cpp
#include "serie.h"
HANDLE OpenSerialPort( char *psPort, // "COM1","COM2"
DWORD dwBaudRate, // CBR_9600, CBR_19200. CBR_56000
BYTE bByteSize, // 7,8
BYTE bParity, // NOPARITY, EVENPARITY, ODDPARITY
BYTE bStopBits, // ONESTOPBIT, ONE5STOPBITS, TWOSTOPBITS
DWORD Timeout // Timeout
) {
HANDLE hPort; // port handler
DCB dcbPort; // Port configuration
COMMTIMEOUTS commTimeouts; // Port Timeouts
DWORD dwError; // Error code
// Open Serial Port
hPort=CreateFile(
psPort, // pointer to name of the file
GENERIC_READ | GENERIC_WRITE, // access (read-write) mode
0, // share mode: 0 the object cannot be share
NULL, // pointer to security attributes: NULL the handle cannot be inherited
OPEN_EXISTING, // how to create: Comx exist
0, // file/port attributes
NULL); // handle to file/port with attributes to copy
// If the function fails, the return value
//is INVALID_HANDLE_VALUE
if ( hPort == INVALID_HANDLE_VALUE ) {
dwError = GetLastError (); // Flush error code
return hPort;
}
// Set Port Configuration
// Delete DCB configuration
FillMemory(&dcbPort, sizeof(dcbPort), 0);
dcbPort.DCBlength = sizeof(dcbPort);
// Current DCB in use for the communications port
GetCommState (hPort, &dcbPort);
// Update DCB with new parameters
dcbPort.BaudRate = dwBaudRate;
dcbPort.ByteSize = bByteSize;
dcbPort.Parity = bParity;
dcbPort.StopBits = bStopBits;
// Fixed parameters (Disable XON-XOFF and modem handshake)
dcbPort.fBinary = TRUE; // Binary mode; no EOF check
dcbPort.fParity = TRUE; // Enable parity checking
dcbPort.fOutxCtsFlow = FALSE; // No CTS output flow control
dcbPort.fOutxDsrFlow = FALSE; // No DSR output flow control
dcbPort.fDtrControl = DTR_CONTROL_ENABLE;
// DTR flow control type
// Raises the DTR line when the device is opened
dcbPort.fDsrSensitivity = FALSE; // DSR sensitivity
dcbPort.fTXContinueOnXoff = TRUE; // XOFF continues Tx
dcbPort.fOutX = FALSE; // No XON/XOFF out flow control
dcbPort.fInX = FALSE; // No XON/XOFF in flow control
dcbPort.fErrorChar = FALSE; // Disable error replacement
dcbPort.fNull = FALSE; // Disable null stripping
dcbPort.fRtsControl = RTS_CONTROL_ENABLE;
// RTS flow control
// Raises the RTS line when the device is opened
dcbPort.fAbortOnError = FALSE; // Do not abort reads/writes on
// error
// Set new configuration
if (!SetCommState (hPort, &dcbPort)) {
dwError = GetLastError (); // Flush error code
CloseSerialPort(hPort);
hPort = INVALID_HANDLE_VALUE;
return hPort;
}
// Set Port Timeouts
// Timeouts preparation MORE INFORMATION IN WIN32 API: COMMTIMEOUTS
commTimeouts.ReadIntervalTimeout = 0; // Specifies the maximum time, in milliseconds, allowed to elapse between the arrival
// of two characters on the communications line
// A value of zero indicates that interval time-outs are not used.
commTimeouts.ReadTotalTimeoutMultiplier = 50; // Specifies the multiplier, in milliseconds, used to calculate
// the total time-out period for read operations.
// For each read operation, this value is multiplied
// by the requested number of bytes to be read.
commTimeouts.ReadTotalTimeoutConstant = Timeout;// Specifies the constant, in milliseconds, used to calculate the total
// time-out period for read operations
//
commTimeouts.WriteTotalTimeoutMultiplier = 10; // Specifies the multiplier, in milliseconds, used to calculate the
// total time-out period for write operations.
// For each write operation, this value is multiplied
// by the number of bytes to be written.
commTimeouts.WriteTotalTimeoutConstant = 1000; // Specifies the constant, in milliseconds, used to calculate the total time-out period
// for write operations
// See de win32 api for more information
// Set Timeouts
if (!SetCommTimeouts (hPort, &commTimeouts)) {
dwError = GetLastError (); // Flush error code
CloseSerialPort(hPort);
hPort = INVALID_HANDLE_VALUE;
return hPort;
}
return hPort;
}
BOOL SerialSendByte(HANDLE hPort, BYTE byte){
BOOL bRes;
DWORD dwError, dwNumBytesWritten=0;
bRes=WriteFile(
hPort, // handle to file or serial port to write to
&byte, // pointer to data to write to file
1, // number of bytes to write
&dwNumBytesWritten, // pointer to number of bytes written
NULL // NULL
);
if ((!bRes)||(dwNumBytesWritten!=1)){
dwError = GetLastError (); // Flush error code
}
return bRes;
}
BOOL SerialReceiveByte(HANDLE hPort, BYTE *pbyte, BOOL *pTimeout){
BOOL bRes;
DWORD dwError, lpNumberOfBytesRead=0;
*pTimeout=FALSE;
bRes=ReadFile( hPort, // handle of file or serial port to read
pbyte, // address of buffer that receives data
1, // number of bytes to read
&lpNumberOfBytesRead, // address of number of bytes read
NULL // NULL
);
if (!bRes) {
dwError = GetLastError (); // Flush error code
}
if ((bRes)&&(lpNumberOfBytesRead==0)){
*pTimeout = TRUE;
}
return bRes;
}
BOOL CloseSerialPort(HANDLE hPort){
BOOL bRes;
DWORD dwError;
bRes=CloseHandle(hPort);
if (!bRes) {
dwError = GetLastError (); // Flush error code
}
return bRes;
}
///////////////////////////////////////////////////////////////////////////////////////////////////
#include "serie.h"
#include "windows.h"
#include "stdio.h"
#include <stdint.h>
int main(){
HANDLE hPort;
BOOL bRes;
BYTE byte;
BOOL timeout;
hPort=OpenSerialPort("COM1",CBR_9600,8,NOPARITY,TWOSTOPBITS,5000);
if (hPort==INVALID_HANDLE_VALUE){
printf("Error abriendo puerto com1");
return 1;
}
while(1){
bRes=SerialReceiveByte(hPort,&byte,&timeout);
if (!bRes) {
break;
}
if (timeout){
printf("\n--->timeout\n");
}
else
{
putchar(byte);
}
}
if (!bRes) {
printf("Error leyendo de puerto com1");
return 1;
}
CloseSerialPort(hPort);
return 0;