View Full Version : INTERFACCIAMENTO SERIALE VB O C++
[NoS]-roby87
10-02-2006, 16:31
salve raga devo creare un programma o in visual basici o c++ che dovrò interfacciare con la porta seriale con un circuito che ho creato aventi dei tasti direzionali e uno INVIO.
con i tasti direzionali mi muoverò diciamo a mo di scacchiera dove in ogni quadratino c'è una materia.
arrivato sul quel determinato quadrettino premo INVIO e mi deve apire la pagina con la tesina riguardante la materia stessa.
vorrei avere qualche dritta sul prog in questione.
specialmente sapere le linee d'istruzione dell'interfacciamento seriale al circuito (qualche link che ne parla).
grazie a tutti.
ciao ciao :D :D :D
Questo è un esempio preso da MSDN:
#include <windows.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
DCB dcb;
HANDLE hCom;
BOOL fSuccess;
char *pcCommPort = "COM2";
hCom = CreateFile( pcCommPort,
GENERIC_READ | GENERIC_WRITE,
0, // must be opened with exclusive-access
NULL, // no security attributes
OPEN_EXISTING, // must use OPEN_EXISTING
0, // not overlapped I/O
NULL // hTemplate must be NULL for comm devices
);
if (hCom == INVALID_HANDLE_VALUE)
{
// Handle the error.
printf ("CreateFile failed with error %d.\n", GetLastError());
return (1);
}
// Build on the current configuration, and skip setting the size
// of the input and output buffers with SetupComm.
fSuccess = GetCommState(hCom, &dcb);
if (!fSuccess)
{
// Handle the error.
printf ("GetCommState failed with error %d.\n", GetLastError());
return (2);
}
// Fill in DCB: 57,600 bps, 8 data bits, no parity, and 1 stop bit.
dcb.BaudRate = CBR_57600; // set the baud rate
dcb.ByteSize = 8; // data size, xmit, and rcv
dcb.Parity = NOPARITY; // no parity bit
dcb.StopBits = ONESTOPBIT; // one stop bit
fSuccess = SetCommState(hCom, &dcb);
if (!fSuccess)
{
// Handle the error.
printf ("SetCommState failed with error %d.\n", GetLastError());
return (3);
}
printf ("Serial port %s successfully reconfigured.\n", pcCommPort);
return (0);
}
Dopo che hai settato i dati devi usare WriteFile e ReadFile per accederci...
mpattera
10-02-2006, 19:18
in visual basic c'è il controllo mscomm
la sclta tra vc e vb la fai tu, se non ti disturbano le librerie a runtime io andrei per vb, è più semplice e immediato se non hai molta esperienza.
// Fill in DCB: 57,600 bps, 8 data bits, no parity, and 1 stop bit.
dcb.BaudRate = CBR_57600; // set the baud rate
dcb.ByteSize = 8; // data size, xmit, and rcv
dcb.Parity = NOPARITY; // no parity bit
dcb.StopBits = ONESTOPBIT; // one stop bit
Riguardo al settaggio del dcb per il controllo di flusso puoi aiutarmi?
Ovvero..come faccio a settarlo correttamente per utilizzare
l'handshaking hardware?E quello software?E per disabilitarlo? :confused:
Perchè ho letto un sacco di versioni discordanti, una (http://www.edavies.nildram.co.uk/win32-serial-bug/index.html) delle quali parla anche
di un bug di gestione del medesimo in certe circostanze.. :eek:
Dimenticavo..
io di solito uso questo switch :
case EHandshakeOff:
dcb.fOutxCtsFlow = false;// Disable CTS monitoring
dcb.fOutxDsrFlow = false;// Disable DSR monitoring
dcb.fDtrControl = DTR_CONTROL_DISABLE;// Disable DTR monitoring
dcb.fOutX = false;// Disable XON/XOFF for transmission
dcb.fInX = false;// Disable XON/XOFF for receiving
dcb.fRtsControl = RTS_CONTROL_DISABLE;// Disable RTS (Ready To Send)break;
case EHandshakeHardware:
dcb.fOutxCtsFlow = true;// Enable CTS monitoring
dcb.fOutxDsrFlow = true;// Enable DSR monitoring
dcb.fDtrControl = DTR_CONTROL_HANDSHAKE;// Enable DTR handshaking
dcb.fOutX = false;// Disable XON/XOFF for transmission
dcb.fInX = false;// Disable XON/XOFF for receiving
dcb.fRtsControl = RTS_CONTROL_HANDSHAKE;// Enable RTS handshaking
break;
case EHandshakeSoftware:
dcb.fOutxCtsFlow = false;// Disable CTS (Clear To Send)
dcb.fOutxDsrFlow = false;// Disable DSR (Data Set Ready)
dcb.fDtrControl = DTR_CONTROL_DISABLE;// Disable DTR (Data Terminal Ready)
dcb.fOutX = true;// Enable XON/XOFF for transmission
dcb.fInX = true;// Enable XON/XOFF for receiving
dcb.fRtsControl = RTS_CONTROL_DISABLE;// Disable RTS (Ready To Send)
break;
Attendo pareri :)
Hai bisogno di gestire tutti questi casi ?!?!?
si putroppo..l'applicazione va ad interagire con apparecchiature elettroniche
diverse (con diverso controllo di flusso) :
a seconda dell'apparecchiatura che vi è collegata seleziona
il relativo controllo di flusso (che la medesima gli comunica)
vBulletin® v3.6.4, Copyright ©2000-2025, Jelsoft Enterprises Ltd.