Apr 30, 2010 08:36 AM
(This post was last modified: Apr 30, 2010 04:19 PM by codepoet.)
The purpose for this code is to turn on the output of the RTS or DTS line of a serial port if the file size changes. I currently use this to turn on a relay that alerts me if I receive new mail in Thunderbird. There is no error checking.
Declarations:
Code:
orignally written by:Ryan Welsh
Declarations:
Code
Imports System.IOCode:
Code
Imports System.IO
'You will get an error if you do not have a file in the path directory that is listed in TextBox1
Public Class Form1
Dim path As String
Dim test1 As Integer
Dim test2 As Integer
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
test2 = test1
End Sub
Private Function GetFileSize(ByVal MyFilePath As String) As Long
Dim MyFile As New FileInfo(MyFilePath)
Dim FileSize As Long = MyFile.Length
Return FileSize
End Function
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
'Change the number if you want a diffent serial port
SerialPort1.Open()
path = TextBox1.Text
Label1.Text = GetFileSize(path)
test1 = Label1.Text
test2 = Label1.Text
End Sub
Private Sub Timer1_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Timer1.Tick
path = TextBox1.Text
Label1.Text = GetFileSize(path)
test1 = Label1.Text
If test1 <> test2 Then
Label2.BackColor = Color.Red
'This is for RTS as a output
'SerialPort1.RtsEnable = True
SerialPort1.DtrEnable = True
Else
Label2.BackColor = Color.Black
'This is for RTS as a output
'SerialPort1.RtsEnable = False
SerialPort1.DtrEnable = False
End If
End Sub
End Classorignally written by:Ryan Welsh
If You Like this tutorial,
please check out my other tutorials by clicking ==> here
please check out my other tutorials by clicking ==> here
PHP & .NET Contributor.

