hallo erst einmal an alle, bin der neue von neben an ...
ich habe volgendes problem ...
ich erhalte keine Gültige Antwort mehr von meiner gegestelle mehr ..
was wurde geändert - der Hardware programiere hat das Parity von NONE auf Even geändert,
eigentlich kein Problem, änder ich das halt auch in meinen Code ... denkste ...
was muss ich berückstigen das die Gegestelle wieder Antwortet ...???
Option Explicit On
Option Strict Off
Imports System.Threading
Imports System
Imports System.IO.Ports
Imports System.Timers
Imports System.IO
Public Class Form1
'02 03 01 00 00 14 44 0a
Private Sub RS232_Click(sender As System.Object, e As System.EventArgs) _
Handles RS232.Click
Try
SerialPort1.Write({(Chr(&H2)), (Chr(&H3)), (Chr(&H1)), (Chr(&H0)), ( _
Chr(&H0)), (Chr(&H14)), (Chr(&H44)), (Chr(&HA))}, 0, 8)
Thread.Sleep(1000)
SerialPort1.Write({&H2, &H3, &H1, &H0, &H0, &H14, &H44, &HA}, 0, 8)
Thread.Sleep(1000)
SerialPort1.Write({&H1, &H3, &H1, &H0, &H0, &H14, &H44, &H39}, 0, 8)
Thread.Sleep(1000)
Dim Inputhex As String
Dim sende As String
Inputhex = crc.Hex2(2) & crc.Hex2(3) & crc.Hex2(1) & crc.Hex2(0) & _
crc.Hex2(0) & crc.Hex2(20)
Dim byteBuffer As Byte() = New Byte(0) {} 'Buffer mit 1 Byte
sende = CRC.AppendModbusCRC16(Inputhex) '# Übergabe des CRC Wertes
' an Var. Sende
For x = 0 To sende.Length \ 2 - 1 '# Sende einheit
byteBuffer(0) = Convert.ToByte(sende.Substring(x * 2, 2), 16) _
'# String wird in Byte Gewandelt
SerialPort1.Write(byteBuffer, 0, byteBuffer.Length) '# Senden
' der Bytes
Next x ' # ende der sendeeinheit
'SerialPort1.Close()
Catch ex As Exception
End Try
End Sub
Private Sub Form1_close(sender As Object, e As _
System.Windows.Forms.ControlEventArgs) Handles Me.ControlAdded
SerialPort1.Close()
End Sub
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) _
Handles MyBase.Load
cmbBaud.SelectedIndex = 4
cmbDataBit.SelectedIndex = 1
cmbParity.SelectedIndex = 2
cmbStopBit.SelectedIndex = 0
For Each s As String In SerialPort.GetPortNames()
cmbPort.Items.Add(s)
Next s
cmbPort.SelectedIndex = 2
End Sub
Private Sub btOpenCOM_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles btOpenCOM.Click
Try
SerialPort1.PortName = cmbPort.Text
SerialPort1.BaudRate = Integer.Parse(cmbBaud.Text)
SerialPort1.DataBits = Integer.Parse(cmbDataBit.Text)
SerialPort1.Parity = Integer.Parse(cmbParity.Text)
If cmbParity.Text.Substring(0, 1) = "0" Then
SerialPort1.Parity = Parity.None
ElseIf cmbParity.Text.Substring(0, 1) = "1" Then
SerialPort1.Parity = Parity.Odd
ElseIf cmbParity.Text.Substring(0, 1) = "2" Then
SerialPort1.Parity = Parity.Even
ElseIf cmbParity.Text.Substring(0, 1) = "3" Then
SerialPort1.Parity = Parity.Mark
End If
If cmbStopBit.Text = "0" Then
SerialPort1.StopBits = StopBits.None
ElseIf cmbStopBit.Text = "1" Then
SerialPort1.StopBits = StopBits.One
End If
btOpenCOM.Enabled = False
btnCloseCOM.Enabled = True
SerialPort1.Open()
comOpen = SerialPort1.IsOpen
Catch ex As Exception
MsgBox(" es ist ein Feheler Aufgetreten !!!!")
End Try
End Sub
Private Sub btnCloseCOM_Click(ByVal sender As System.Object, ByVal e As _
System.EventArgs) Handles btnCloseCOM.Click
SerialPort1.Close()
btOpenCOM.Enabled = True
btnCloseCOM.Enabled = False
End Sub
'#######################################
End Class währe super wenn mir da jemand weiter helfen könnte ...
ist nur zu Testen das Projekt weil ich noch ander Probleme habe,
also nicht gleich Schimpfen
Danke im Voraus ...
Michael MP Profitlich |