Questo sito utilizza cookies solo per scopi di autenticazione sul sito e nient'altro. Nessuna informazione personale viene tracciata. Leggi l'informativa sui cookies.
Username: Password: oppure
C# / VB.NET - Problemi nella conversione di codice da processing a VB.net
Forum - C# / VB.NET - Problemi nella conversione di codice da processing a VB.net

Avatar
robyfertz (Normal User)
Newbie


Messaggi: 1
Iscritto: 09/08/2011

Segnala al moderatore
Postato alle 20:48
Martedì, 09/08/2011
Buongiorno a tutti !!!!
Premessa : sono un perito elettronico quindi Hardware no problem, conosco VB e stò cominciando a divertirmi con VB.Net ( e qui son dolori) quindi portate pazienza…
Ora veniamo alla richiesta :
devo comandare, dal programma che sto scrivendo con vb9, una scheda che viene venduta con il suo software di gestione fatto in Processing.
Compito di questo s/w è quello di inviare via seriale dei comandi alla scheda...

Ora sono giorni che tento di "convertire" la sub di questo programma che esegue prima la costruzione dell'array da trasmettere e poi la trasmissione dei dati appunto in vb9 ma senza successo....

A questa sub  vengono passate da altre sub le seguenti variabili :
id : che è l'indirizzo della scheda (nel nostro caso è sempre uguale a 0)
Cmd : che sono dei caratteri ascii (il comando vero e proprio)
ValueLen : che è il numero di parametri da spedire ( ogni comando spedisce un diverso  numero di parametri)
IntFlag : che è il tipo dei parametri da spedire

La descrizione del protocollo di trasmissione la potete trovare nel file zip allegato….

Quindi riassumendo la sub che devo scrivere in vb9 deve, dopo essere stata chiamata, prendere le 4 variabili che ho scritto sopra ( id,Cmd, ValueLen e IntFlag)
che vengono di volta in volta modificate da altre sezioni del programma, costruire un array che rispetti il protocollo di trasmissione che ho allegato e trasmettere infine questo array via seriale..

codice da convertire :                                                                                        

Codice sorgente - presumibilmente C++

  1. void TxData(int Id, int Cmd, int ValueLen, int IntFlag)                                                            {                                                                                                                                      /* Transmit a string toward dsNavCon board                                                                        */                                                                                                                                      
  2.    int TxBuffCount;
  3.    int ChkSum = 0;        
  4.    int CmdLen = 0;
  5.    if (IntFlag == 0) // byte value
  6.    {                                                                                                                                                          
  7.       CmdLen = ValueLen;
  8.       for (TxBuffCount = 0; TxBuffCount < ValueLen; TxBuffCount++)
  9.      {
  10.         TxBuff[(TxBuffCount*2)+TxHeadLen] = (byte)(TxIntValue[TxBuffCount]);
  11.       }
  12.    }
  13.    if (IntFlag == 1) // integer value
  14.    {
  15.       CmdLen = ValueLen*2; // 1 int value = 2 bytes to transmit
  16.       for (TxBuffCount = 0; TxBuffCount < ValueLen; TxBuffCount++)
  17.       {
  18.          TxBuff[(TxBuffCount*2)+TxHeadLen] = (byte)(TxIntValue[TxBuffCount] >> 8);
  19.          TxBuff[(TxBuffCount*2)+TxHeadLen+1] = (byte)(TxIntValue[TxBuffCount]);
  20.       }
  21.    }
  22.  
  23.    if (IntFlag == 2) // long value
  24.    {
  25.       CmdLen = ValueLen*4; // 1 long value = 4 bytes to transmit
  26.       for (TxBuffCount = 0; TxBuffCount < ValueLen; TxBuffCount++)
  27.       {
  28.          TxBuff[(TxBuffCount*4)+TxHeadLen] = (byte)(TxIntValue[TxBuffCount] >> 24);
  29.          TxBuff[(TxBuffCount*4)+TxHeadLen+1] = (byte)(TxIntValue[TxBuffCount] >> 16);
  30.          TxBuff[(TxBuffCount*4)+TxHeadLen+2] = (byte)(TxIntValue[TxBuffCount] >> 8);
  31.          TxBuff[(TxBuffCount*4)+TxHeadLen+3] = (byte)(TxIntValue[TxBuffCount]);
  32.       }
  33.    }
  34.  
  35.    TxBuff[0] = (byte)('@');
  36.    TxBuff[1] = (byte)(Id);
  37.    TxBuff[2] = (byte)(Cmd);
  38.    TxBuff[3] = (byte)(CmdLen+1); // included CheckSum
  39.  
  40.    for (i=0;i<(TxHeadLen+CmdLen);i++)
  41.    {
  42.       ChkSum += TxBuff[ i ];
  43.    }
  44.    TxBuff[TxHeadLen+CmdLen] = (byte)(ChkSum);
  45.  
  46.    for (i=0;i<(TxHeadLen+CmdLen+1);i++)
  47.    {
  48.       RS232Port.write(TxBuff[ i ]);
  49.    }
  50.  
  51.    if (IntFlag != 3) TxFlag = true; // avoid to blink TX led for continuos send
  52. }




Il problema è che quando vado in trasmissione I caratteri sono convertiti in decimale e non in esadecimale (questo perlomeno è quello che vedo con un monitor sulla seriale) e quindi la scheda non funge…..

Grazie mille per le eventuali risposte…….


robyfertz ha allegato un file: dsNav communication.zip (192406 bytes)
Clicca qui per scaricare il file

Ultima modifica effettuata da Il Totem il 10/08/2011 alle 11:13
PM
Avatar
Il Totem (Admin)
Guru^2


Messaggi: 3635
Iscritto: 24/01/2006

Up
1
Down
V
Segnala al moderatore
Postato alle 11:18
Mercoledì, 10/08/2011
Un carattere sta sempre in un byte. Il fatto di vederlo come ascii, come numero in base 10 o come numero in base 16 è semplicemente una questione di lettura e decodifica. Il contenuto reale in memoria, o, come in questo caso, sullo stream, è sempre lo stesso byte. Quindi questo non può essere l'errore che cerchi.
Per il resto il codice è uguale a quello fornito nel documento, perciò dovresti fornire il sorgente in vb che tu hai tradotto: è lì che probabilmente si troverà l'errore.

PM