Home Page
Articoli
Tips & Tricks
News
Forum
Archivio Forum
Blogs
Sondaggi
Rss
Video
Utenti
Chi Siamo
Contattaci
Username:
Password:
Login
Registrati ora!
Recupera Password
Home Page
Stanze Forum
App. WinForms / WPF .NET
Conversione di una sezione di programma da Processing a VB9
martedì 02 agosto 2011 - 00.40
Elenco Threads
Stanze Forum
Aggiungi ai Preferiti
Cerca nel forum
Elenco Tags
VB.NET
|
.NET 4.0
|
Windows XP
|
Visual Studio 2008
robyfertz
Profilo
| Newbie
1
messaggi | Data Invio:
mar 2 ago 2011 - 00:40
ciao a tutti !
Sono un perito elettronico appassionato di robotica, al livello hobbystico, quindi per la parte hardware no problem mentre per la parte software son dolori.....
Premesso ciò vengo al punto....
devo comandare dal programma che sto scrivendo con vb9 una scheda che mi consente di comandare i driver dei motori che ho sul robot...
Questa scheda viene venduta con il suo software di gestione fatto in Processing che appunto invia i comandi, via seriale, alla scheda...
Ora sono giorni che tento di "convertire" la parte di codice di questo programma che esegue prima la costruzione dell'array da trasmettere e poi la trasmissione appunto in vb9 ma senza successo....
C'è qualche anima volenterosa che mi possa fare la conversione delle poche seguenti righe di codice in vb9 ??
NOTA : a questa parte di codice vengono passate da altre sub le seguenti variabili :
id : l'indirizzo della scheda che è sempre uguale a 0
Cmd : che sono dei caratteri ascii
ValueLen : che è il numero di parametri da spedire
IntFlag : che è il tipo dei parametri da spedire
Il protocollo di trasmissione è il seguente :
Command strings are variable length type. Any string is composed by an array of N unsigned char:
Pos. Name Values range Description
0 Header @ Always present. Needed to synchronize communication
1 Id 0-9 ASCII The id of the board addressed by this command. Not used here, may be used if more devices are present
2 Cmd ASCII All ASCII printable characters may be used
3 CmdLen Binary Number (N) of bytes following (checksum included)
... data 0
...
... data x
N Checksum 0-255 obtained by simply adding up in a 8 bit variable, all bytes that compose the message (checksum itself excluded)
codice da convertire :
/*-----------------------------------------------------------------------------*/
void TxData(int Id, int Cmd, int ValueLen, int IntFlag)
{
/* Transmit a string toward dsNavCon board
for a detailed description of protocol, see descrEng.txt in dsPID33 folder
*/
int TxBuffCount;
int ChkSum = 0;
int CmdLen = 0;
if (PreInitRS232Flag || SimulationRS232Flag) // RS232 not ready or simulation
{
return;
}
if (IntFlag == 0) // byte value
{
CmdLen = ValueLen;
for (TxBuffCount = 0; TxBuffCount < ValueLen; TxBuffCount++)
{
TxBuff[(TxBuffCount*2)+TxHeadLen] = (byte)(TxIntValue[TxBuffCount]);
}
}
if (IntFlag == 1) // integer value
{
CmdLen = ValueLen*2; // 1 int value = 2 bytes to transmit
for (TxBuffCount = 0; TxBuffCount < ValueLen; TxBuffCount++)
{
TxBuff[(TxBuffCount*2)+TxHeadLen] = (byte)(TxIntValue[TxBuffCount] >> 8);
TxBuff[(TxBuffCount*2)+TxHeadLen+1] = (byte)(TxIntValue[TxBuffCount]);
}
}
if (IntFlag == 2) // long value
{
CmdLen = ValueLen*4; // 1 long value = 4 bytes to transmit
for (TxBuffCount = 0; TxBuffCount < ValueLen; TxBuffCount++)
{
TxBuff[(TxBuffCount*4)+TxHeadLen] = (byte)(TxIntValue[TxBuffCount] >> 24);
TxBuff[(TxBuffCount*4)+TxHeadLen+1] = (byte)(TxIntValue[TxBuffCount] >> 16);
TxBuff[(TxBuffCount*4)+TxHeadLen+2] = (byte)(TxIntValue[TxBuffCount] >> 8);
TxBuff[(TxBuffCount*4)+TxHeadLen+3] = (byte)(TxIntValue[TxBuffCount]);
}
}
TxBuff[0] = (byte)('@');
TxBuff[1] = (byte)(Id);
TxBuff[2] = (byte)(Cmd);
TxBuff[3] = (byte)(CmdLen+1); // included CheckSum
for (i=0;i<(TxHeadLen+CmdLen);i++)
{
ChkSum += TxBuff[i];
}
TxBuff[TxHeadLen+CmdLen] = (byte)(ChkSum);
for (i=0;i<(TxHeadLen+CmdLen+1);i++)
{
RS232Port.write(TxBuff[i]);
}
if (IntFlag != 3) TxFlag = true; // avoid to blink TX led for continuos send
}
Vi ringrazio in anticipo per ogni eventuale aiuto .....
Torna su
Stanze Forum
Elenco Threads
Partecipa anche tu! Registrati!
Hai bisogno di aiuto ?
Perchè non ti registri subito?
Dopo esserti registrato potrai chiedere
aiuto sul nostro
Forum
oppure aiutare gli altri
Consulta le
Stanze
disponibili.
Registrati ora !