2022年6月26日 星期日

自行車租借WebAPP系統-完整版

 


歡迎需要客製開發 WebAPP.WebAPI 系統的客戶

都可以加LINE與我聯絡

可以開發任何行業系統,包含硬體串接.各種金流串接及超商系統

也能開立電子發票.點餐系統.工廠BOM.進銷存.POS...等等

Google查 : 池龍工作室








2022年6月17日 星期五

vb.net利用SerialPort進行讀取串口操作

 Imports System

Imports System.IO.Ports


Public Class Form1


Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

'獲取計算機有效串口

        Dim ports As String() = SerialPort.GetPortNames() '必須用命名空間,用SerialPort,獲取計算機的有效串口

        Dim port As String

For Each port In ports

            portnamebox.Items.Add(port) '向combobox中添加項

        Next port

'初始化界面

        baudratebox.SelectedIndex() = 2

        portnamebox.SelectedIndex() = 0

        Serial_Port1() '初始化串口

        Label3.Text = SerialPort1.IsOpen

        statuslabel.Text = "串口未連接"

        statuslabel.ForeColor = Color.Red

        sendbox.Text = "123"

' baudratebox.Text = baudratebox.Items(0) 註釋和不註釋的地方可以替換

        'portnamebox.Text = portnamebox.Items(0)

    End Sub


Private Sub Serial_Port1() '設置串口參數

        SerialPort1.BaudRate = Val(baudratebox.Text) '波特率

        SerialPort1.PortName = portnamebox.Text '串口名稱

        SerialPort1.DataBits = 8 '數據位

        SerialPort1.StopBits = IO.Ports.StopBits.One '停止位

        SerialPort1.Parity = IO.Ports.Parity.None '校驗位

    End Sub


'關閉串口連接

    Private Sub closebtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles closebtn.Click

Try

            SerialPort1.Close() '關閉串口

            Label3.Text = SerialPort1.IsOpen

If SerialPort1.IsOpen = False Then

                statuslabel.Text = "串口未連接"

                statuslabel.ForeColor = Color.Red

                receivebox.Text = ""

                receivebytes.Text = ""

End If

Catch ex As Exception

            MessageBox.Show(ex.Message)

End Try

End Sub


'打開串口連接

    Private Sub openbtn_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles openbtn.Click

Try

            SerialPort1.Open() '打開串口

            Label3.Text = SerialPort1.IsOpen

If SerialPort1.IsOpen = True Then

                statuslabel.Text = "串口已連接"

                statuslabel.ForeColor = Color.Green

End If

Catch ex As Exception

            MessageBox.Show(ex.Message)

End Try

End Sub



'發送數據

    Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Try

            SerialPort1.Write(sendbox.Text)

Catch ex As Exception

            MessageBox.Show(ex.Message)

End Try


End Sub


'觸發接收事件

    Public Sub Sp_DataReceived(ByVal sender As Object, ByVal e As System.IO.Ports.SerialDataReceivedEventArgs) Handles SerialPort1.DataReceived

Me.Invoke(New EventHandler(AddressOf Sp_Receiving)) '調用接收數據函數

    End Sub


'接收數據

    Private Sub Sp_Receiving(ByVal sender As Object, ByVal e As EventArgs)

Dim strIncoming As String

Try

            receivebytes.Text = Str(Val(receivebytes.Text) + SerialPort1.BytesToRead)

If SerialPort1.BytesToRead > 0 Then

                Threading.Thread.Sleep(100) '添加的延時

                strIncoming = SerialPort1.ReadExisting.ToString '讀取緩衝區中的數據

                SerialPort1.DiscardInBuffer()

                receivebox.Text = strIncoming

End If

Catch ex As Exception

            MessageBox.Show(ex.Message)

End Try

End Sub

End Class

2022年6月10日 星期五

IIS 檔案上傳的大小限制 File Upload Limit (MaxRequestLength, MaxAllowedContentLength)

 IIS 檔案上傳的大小限制 File Upload Limit (MaxRequestLength, MaxAllowedContentLength)


藉由調整 maxAllowedContentLength來設定 IIS 所允許的檔案上傳大小,預設值為 30000000 相當於 28.6 MB,調整為 104857600 相當於 100 MB。


<system.webServer>

    <security>

        <requestFiltering>

            <requestLimits maxAllowedContentLength="104857600" />

        </requestFiltering>

    </security>

</system.webServer>


另外也可以使用 GUI 來設定:




2022年6月8日 星期三

FileRead and StreamReader介紹開啟檔案的幾個方法

 


以下程式碼, 由上而下分別是: 

(1) 以 File.Open 讀檔 

(2) 以 StreamReader 讀檔(此方法比較簡便) 

(3) 以 File 類別支援的 ReadAllText 方法, 讀出整個檔案內容. 

(4) StreamReader 搜尋檔案裡是否存在某個字串. 


因為程式碼都很簡單, 就不多做解釋, 請直接看以下所附的 code 應該不難了解. 



Imports System.IO

 

Public Class _03_StreamReader

 

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click

Dim theFile As FileStream = File.Open("d:\temp\asdf.txt", FileMode.Open, FileAccess.Read)

Dim rdr As StreamReader = New StreamReader(theFile)

TextBox1.Text = rdr.ReadToEnd()

rdr.Close()

theFile.Close()

End Sub

 

 

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button2.Click

Dim rdr As StreamReader = File.OpenText("d:\temp\asdf.txt")

TextBox1.Text = rdr.ReadToEnd()

rdr.Close()

End Sub

 

 

Private Sub Button3_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button3.Click

MsgBox(File.ReadAllText("d:\temp\asdf.txt"))

End Sub

 

 

Private Sub Button4_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button4.Click

Dim rdr As StreamReader = File.OpenText("d:\temp\asdf.txt")

While Not rdr.EndOfStream

Dim ft As String = rdr.ReadLine()

If ft.Contains(TextBox2.Text) Then

MsgBox("Found " & TextBox2.Text & vbNewLine & ft)

End If

End While

End Sub

 

 

End Class