#1 30. August 2007 Harwaremodul per Software ansteuern Ich interessiere mich für ein spezielles Problem. Hier erstmal ein Weblink dazu: http://www.talentraspel.de/portal/index.php?id=139&type=1 Kann mir jemand einen Abriss geben, wie man von einer Com- bzw. USB-Schnittstelle ein selbsterstelltes Hardwaremodul ansprechen kann? Es darf ruig einfach erklärt werden *g*. Ich weis, für sowas studieren manche Technische Informatik aber ich interessiere mich für diese Verbindung zwischen Software und Modul sehr. Es dürfen auch erklärende Weblinks gepostet werden. Danke schonmal im Voraus + Multi-Zitat Zitieren
#2 30. August 2007 AW: Harwaremodul per Software ansteuern Hi, versuchs mal mit dem Code. Code: Imports System.Windows.Forms.Application Imports System.Security.Principal Imports System.Text Imports System.IO.Ports Imports System.Timers Imports System.IO Public Class Hauptfenster Inherits System.Windows.Forms.Form Dim objDateiMacher As New System.IO.StreamWriter("data.txt") Dim WithEvents SerialPort As New System.IO.Ports.SerialPort("COM3", 115200, Parity.None, 8, StopBits.One) Private Delegate Sub DelegateSub() Dim buf As String Dim Programm As String Dim StateConnection As Boolean Dim Connecting As New System.Threading.Thread(AddressOf CommStart) Private TextboxAktualisieren As New DelegateSub(AddressOf Wertübergabe) Public Sub Me_Closed(ByVal sender As Object, ByVal e As System.Windows.Forms.FormClosedEventArgs) Handles MyBase.FormClosed objDateiMacher.Close() End Sub Public Sub CommStart() With SerialPort Do Until .IsOpen DoEvents() Try .Open() Catch ex As Exception : StateConnection = True End Try If StateConnection Then ProgressBar1.Visible = True End If Loop End With StateConnection = False ProgressBar1.Visible = False End Sub Public Sub CommStop() With SerialPort .Close() End With End Sub Public Sub SerialPort_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort.DataReceived For i As Int32 = 0 To SerialPort.BytesToRead ' Alle Bytes einzel lesen und anzeigen Try Dim buf As Byte() = {SerialPort.BaseStream.ReadByte} Dim enc As New System.Text.ASCIIEncoding() Programm = enc.GetString(buf) Programm = Programm.Replace(Chr(13), Nothing) objDateiMacher.Write(Programm) Me.Invoke(TextboxAktualisieren) Catch ex As Exception MessageBox.Show("Ein Übertragungsfehler ist aufgetreten.", "Fehler", MessageBoxButtons.OK) End Try Next i End Sub Private Sub DataStart() With SerialPort Dim FomTest As Byte() = {85, 255, 5, 1, 0} If .IsOpen Then .BaseStream.Write(FomTest, 0, 5) Return Else MsgBox(InfoPortClosed + .PortName, MsgBoxStyle.Critical) End If End With End Sub Private Sub NamenStart() With SerialPort Dim FomTest As Byte() = {85, 32, 5, 21, 0} If .IsOpen Then .BaseStream.Write(FomTest, 0, 5) Return Else MsgBox(InfoPortClosed + .PortName, MsgBoxStyle.Critical) End If End With End Sub Private Sub Wertübergabe() TextBox1.AppendText(Programm) End Sub Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click CommStart() End Sub Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click CommStop() End Sub Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click DataStart() End Sub Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click NamenStart() End Sub Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick If SerialPort.IsOpen And Not StateConnection Then Me.Label1.Text = "Schnittstelle geöffnet: " + SerialPort.PortName Else Me.Label1.Text = "Schnittstelle geschlossen: " + SerialPort.PortName End If If StateConnection Then Me.Label1.Text = InfoPortTry End If If Timer1.Enabled And StateConnection Then Timer2.Start() End If End Sub Private Sub Timer2_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer2.Tick Me.Label1.Text = InfoPortBemerkung End Sub Private Sub ProgrammeinstellungenToolStripMenuItem_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ProgrammeinstellungenToolStripMenuItem.Click FanControlX.Einstellungen.Show() End Sub End Class mfg Bloody + Multi-Zitat Zitieren