pb利用NetMessageBufferSend在局域网发送中文消息(实现cmd中 NET SEND功能)

本文介绍了一个用于网络消息发送的工具,其版本已更新以支持发送中文。使用时需确保Messenger服务已启用,并提供了包括创建文件、发送消息等功能的详细说明。
 

         这是一个窗口w_main的导出对象,需要的自己保存为文件,再导入。

        这个版本其实来自网上,只是网上的那个不能发送中文,现在做了修改,支持发送中文了。

        记住,net send 依赖于系统服务Messenger,在使用API函数 NetMessageBufferSend 前必须保证该服务已经启用(需要在程序中自动启用该服务的,可以下载pb操作系统服务——重启MSSQLSERVER 自己整合)。

 

$PBExportHeader$w_main.srw
forward
global type w_main from window
end type
type mle_1 from multilineedit within w_main
end type
type cb_1 from commandbutton within w_main
end type
type sle_1 from singlelineedit within w_main
end type
type st_2 from statictext within w_main
end type
type st_1 from statictext within w_main
end type
type icmp_echo_reply from structure within w_main
end type
end forward

type icmp_echo_reply from structure
    unsignedlong        address
    unsignedlong        status
    unsignedlong        roundtriptime
    unsignedlong        datasize
    unsignedlong        reserved[3]
    character       data[250]
end type

global type w_main from window
integer x = 1056
integer y = 484
integer width = 1531
integer height = 1152
boolean titlebar = true
string title = "NETMESSAGESEND"
boolean controlmenu = true
boolean minbox = true
boolean resizable = true
long backcolor = 80269524
mle_1 mle_1
cb_1 cb_1
sle_1 sle_1
st_2 st_2
st_1 st_1
end type
global w_main w_main

type prototypes
Function ulong IcmpCreateFile () Library "icmp.dll"
Function long IcmpSendEcho (ulong IcmpHandle, ulong DestinationAddress, string RequestData,long RequestSize, long RequestOptions, Ref icmp_echo_reply ReplyBuffer, long ReplySize, long Timeout ) Library "icmp.dll" Alias for "IcmpSendEcho"
Function long IcmpCloseHandle (ulong IcmpHandle) Library "icmp.dll"
Function ulong inet_addr (string cp) Library "ws2_32.dll" Alias for "inet_addr"

Function ulong NetMessageBufferSend(ulong servername, ref char msgname[],ulong fromname, ref char buf[], ulong buflen) Library "netapi32.dll" Alias for "NetMessageBufferSend"
function ulong MultiByteToWideChar(uint codepage, ulong dwflags, ref string lpmultibytestr, int cchmultibyte, ref char lpwidecharstr[], int cchwidechar) library "kernel32.dll" alias for "MultiByteToWideChar"

end prototypes
type variables
CONSTANT ulong NERR_Success = 0

end variables
forward prototypes
public function boolean wf_netmessagebuffersend (string as_sendto, string as_msgtext)
public function boolean wf_ping (string as_ipaddress, string as_echomsg)
public subroutine wf_string2unicode (ref character as_unicode[], string as_string)
end prototypes

public function boolean wf_netmessagebuffersend (string as_sendto, string as_msgtext);Ulong lul_result, lul_buflen

Char lc_msgname[],lc_msgtext[]
string ls1, ls2
wf_string2unicode( lc_msgname, as_sendto)
wf_string2unicode( lc_msgtext, as_msgtext)

lul_buflen = UpperBound(lc_msgtext)

lul_result = NetMessageBufferSend(0, lc_msgname,0, lc_msgtext, lul_buflen)

If lul_result = NERR_Success Then
    Return True
Else
    Return False
End If

end function

public function boolean wf_ping (string as_ipaddress, string as_echomsg);ULong lul_address, lul_handle
Long ll_rc, ll_size
String ls_reply
icmp_echo_reply lstr_reply

lul_address = inet_addr(as_ipaddress)
If lul_address > 0 Then
    lul_handle = IcmpCreateFile()
    ll_size = Len(as_echomsg)
    ll_rc = IcmpSendEcho(lul_handle, lul_address, &
                        as_echomsg, ll_size, 0, &
                        lstr_reply, 278, 200)
    IcmpCloseHandle(lul_handle)
    If ll_rc <> 0 Then
        If lstr_reply.Status = 0 Then
            ls_reply = String(lstr_reply.Data)
            If ls_reply = as_echomsg Then
                Return True
            End If
        End If
    End If
End If
 
Return False

end function

public subroutine wf_string2unicode (ref character as_unicode[], string as_string);char lc_data[]
long ll_len, ll_rc
ll_len = lenw(as_string) * 2
lc_data = space(ll_len)

ll_rc = multibytetowidechar(936, 0, as_string , -1, lc_data, ll_len)

as_unicode = lc_data
as_unicode[upperbound(as_unicode) + 1] = char(0)
as_unicode[upperbound(as_unicode) + 1] = char(0)
end subroutine

on w_main.create
this.mle_1=create mle_1
this.cb_1=create cb_1
this.sle_1=create sle_1
this.st_2=create st_2
this.st_1=create st_1
this.Control[]={this.mle_1,&
this.cb_1,&
this.sle_1,&
this.st_2,&
this.st_1}
end on

on w_main.destroy
destroy(this.mle_1)
destroy(this.cb_1)
destroy(this.sle_1)
destroy(this.st_2)
destroy(this.st_1)
end on

type mle_1 from multilineedit within w_main
integer x = 27
integer y = 264
integer width = 1399
integer height = 604
integer taborder = 20
integer textsize = -10
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "方正姚体"
long textcolor = 33554432
string text = "你好"
borderstyle borderstyle = stylelowered!
end type

type cb_1 from commandbutton within w_main
integer x = 1070
integer y = 904
integer width = 357
integer height = 108
integer taborder = 30
integer textsize = -10
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "方正姚体"
string text = " 发送(&S)"
end type

event clicked;if not wf_ping(trim(sle_1.text),"") then
    messagebox("提示","指定目标地址不存在或不通!")
    return
end if

 

if wf_NetMessageBufferSend(trim(sle_1.text),trim(mle_1.text)) then
   //messagebox("提示","发送成功!")
else
   messagebox("提示","发送失败!")   
end if

end event

type sle_1 from singlelineedit within w_main
integer x = 430
integer y = 48
integer width = 997
integer height = 92
integer taborder = 10
integer textsize = -10
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "方正姚体"
long textcolor = 33554432
string text = "hhyy"
boolean autohscroll = false
borderstyle borderstyle = stylelowered!
end type

type st_2 from statictext within w_main
integer x = 14
integer y = 172
integer width = 379
integer height = 76
integer textsize = -10
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "方正姚体"
long textcolor = 33554432
long backcolor = 67108864
boolean enabled = false
string text = "发送内容:"
boolean focusrectangle = false
end type

type st_1 from statictext within w_main
integer x = 14
integer y = 52
integer width = 379
integer height = 76
integer textsize = -10
integer weight = 400
fontcharset fontcharset = gb2312charset!
fontpitch fontpitch = variable!
string facename = "方正姚体"
long textcolor = 33554432
long backcolor = 67108864
boolean enabled = false
string text = "目标地址:"
boolean focusrectangle = false
end type


 

本课题旨在设计并实现一套以STM32微控制器为核心的智慧农业灌溉系统。该系统集成土壤湿度、温湿度、光照强度等多种传感器与水泵、电磁阀等执行器,通过实时数据采集与智能决策,实现对农田环境的精准监测、按需灌溉与远程控制,具备低成本、高可靠性与易部署的特点。主要研究内容如下:1.系统总体方案设计: 深入分析智慧农业灌溉系统的功能需求,重点围绕节水效率、控制精度与远程监控能力进行技术可行性论证。设计系统的整体架构,包括硬件架构(主控芯片选型、传感器与执行器配置、电源与通信模块设计)和软件架构(主控制流程、数据处理逻辑、通信协议与用户交互界面) 2.系统硬件电路设计与实现 (1)主控核心电路设计:以STM32F103C8T6微控制器为核心,设计包括电源管理、时钟、复位、调试接口在内的最小系统电路。 (2)传感器采集电路设计:设计土壤湿度传感器、温湿度传感器(如DHT11)、光照传感器等与STM32的接口电路,确保信号稳定与抗干扰能力。 (3)执行器驱动电路设计:设计继电器驱动电路,用于控制水泵、电磁阀等灌溉执行机构,确保驱动能力与电气安全。 (4)通信模块电路设计:集成Wi-Fi模块(如ESP8266)或4G模块,实现STM32与云平台或移动终端的数据交互,设计相应的串口或SPI通信接口电路。 3. 系统软件程序设计与实现: (1)开发环境搭建:基于Keil MDK或STM32CubeIDE搭建软件开发环境,配置HAL库或标准库,完成基本外设初始化。 (2)传感器数据采集与处理:编写传感器驱动代码,实现土壤湿度、温湿度等数据的实时采集,并通过滤波算法与阈值判断提高数据可靠性。 (3) 灌溉控制逻辑实现: 自动灌溉功能:根据土壤湿度阈值自动启停灌溉设备; 环境监控功能实现土壤湿度、水箱剩余水量等传感器的实时数据采集、阈值判断及相应的联动控制逻辑(洒水、启动风扇)。 报警功能实现本地声光报警(蜂鸣器)与远程短信报警的联动机制。 通信协议与远程控制实现:编写程序实现STM32与GSM模块的AT指令交互,完成报警短信的发送实现与手机APP(可通过云服务器或局域网)的数据交互协议,完成状态上报和远程控制指令的解析与执行。
最新发布
10-21
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值