Problema con porta seriale

martedì 04 settembre 2007 - 07.31

lordwaizard Profilo | Senior Member

Ho sviluppato vari applicativi che si connettevano alla porta seriale, senza aver problemi.
L'ultimo però, utilizzando lo stesso codice, non funziona. Il problema è che se apro la porta con il mio programma parte una schermata blu con IRQ_NOT_LESS..... e si inchioda la macchina se mi collego con hyper terminal tutto funziona correttamente.


Grazie a tutti

SO WinXP
VS 2005 Pro

Codice:
Dim ArrDomanda() As Byte = {&H7E, &H80, &H4, &H10, &H20, 0, 0, &H7E}
Dim ArrRispostaByte() As Byte
Dim IndirizzoMittente As Byte = 128
Dim FlagStartStop As Byte = &H7E
Dim FlagDomandaRisposta As Byte = &H10
Dim ArrTLG1(19) As Byte
Dim ArrTLG2(19) As Byte
Dim ArrTLG3(19) As Byte
Dim datimis(5) As Decimal

Public titolo As String = "3S Seriale"

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
For i As Integer = 0 To _
My.Computer.Ports.SerialPortNames.Count - 1
portecom.Items.Add(My.Computer.Ports.SerialPortNames(i))
Next
End Sub


Public Delegate Sub myDelegate()


Private Sub DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort.DataReceived
Try
TextBox1.Invoke(New myDelegate(AddressOf Ricevi), New Object() {})
Catch
MsgBox("Problema in ricezione!", MsgBoxStyle.Exclamation, titolo)
End Try
End Sub

Public Sub Ricevi()
ReDim ArrRispostaByte(0)
SerialPort.ReadTimeout = 20

Try
Do
SerialPort.Read(ArrRispostaByte, ArrRispostaByte.Length - 1, 1)
ReDim Preserve ArrRispostaByte(ArrRispostaByte.Length)
Loop
Catch ex As Exception

End Try
If ArrRispostaByte.Length < 3 Then
Exit Sub
Else
ReDim Preserve ArrRispostaByte(ArrRispostaByte.GetUpperBound(0) - 1)
End If


cmisura.Text = ""
Dim i As Integer = 0
While i <= UBound(ArrRispostaByte)
If ArrRispostaByte(i) <> 13 Then
cmisura.Text &= Convert.ToChar(ArrRispostaByte(i))
End If
i += 1
End While

End Sub

Private Sub ToolStripButton1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ToolStripButton1.Click
connetticom()
End Sub

Private Sub connetticom()
If SerialPort.IsOpen = True Then
SerialPort.Close()
bstato.Text = "Porta " & SerialPort.PortName & " disconnessa."
Else
Try
With SerialPort
.PortName = portecom.Text
.BaudRate = 9600
.Parity = IO.Ports.Parity.None
.DataBits = 8
.StopBits = IO.Ports.StopBits.One
.Handshake = IO.Ports.Handshake.None
End With
SerialPort.Open()

bstato.Text = "Connesso con " & portecom.Text
Catch ex As Exception
MsgBox(ex.ToString)
End Try
End If
End Sub
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 !
Copyright © dotNetHell.it 2002-2024
Running on Windows Server 2008 R2 Standard, SQL Server 2012 & ASP.NET 3.5