{"id":267153,"date":"2023-03-17T06:11:16","date_gmt":"2023-03-16T22:11:16","guid":{"rendered":"https:\/\/lrxjmw.cn\/zwlqrskfyydz.html"},"modified":"2023-03-17T06:11:16","modified_gmt":"2023-03-16T22:11:16","slug":"zwlqrskfyydz","status":"publish","type":"post","link":"https:\/\/lrxjmw.cn\/zwlqrskfyydz.html","title":{"rendered":"\u638c\u63e1Linux\u5d4c\u5165\u5f0f\u5f00\u53d1\u8bed\u8a00\uff0c\u6253\u9020\u667a\u80fd\u786c\u4ef6\u65b0\u65f6\u4ee3"},"content":{"rendered":"
Linux<\/a>\u5d4c\u5165\u5f0f\u5f00\u53d1\u8bed\u8a00\u662f\u667a\u80fd\u786c\u4ef6\u9886\u57df\u7684\u5fc5\u5907\u6280\u80fd\u4e4b\u4e00\u3002\u638c\u63e1\u8be5\u6280\u80fd\u53ef\u4ee5\u8ba9\u4f60\u66f4\u597d\u5730\u7406\u89e3\u548c\u5b9e\u73b0\u5d4c\u5165\u5f0f\u7cfb\u7edf<\/a>\u3002\u672c\u6587\u5c06\u4ece\u96f6\u5f00\u59cb\uff0c\u4e3a\u4f60\u8be6\u7ec6\u4ecb\u7ecdLinux\u5d4c\u5165\u5f0f\u5f00\u53d1\u8bed\u8a00\uff0c\u5e2e\u52a9\u4f60\u6253\u9020\u667a\u80fd\u786c\u4ef6\u65b0\u65f6\u4ee3\u3002<\/p>\n 1.\u4ec0\u4e48\u662fLinux\u5d4c\u5165\u5f0f\u5f00\u53d1\u8bed\u8a00\uff1f<\/p>\n Linux\u5d4c\u5165\u5f0f\u5f00\u53d1\u8bed\u8a00\u662f\u6307\u5728\u5d4c\u5165\u5f0f\u7cfb\u7edf\u4e2d\u4f7f\u7528\u7684\u7f16\u7a0b\u8bed\u8a00\uff0c\u5305\u62ecC\u3001C++\u3001Python\u7b49\u3002\u8fd9\u4e9b\u8bed\u8a00\u901a\u5e38\u7528\u4e8e\u7f16\u5199\u9a71\u52a8\u7a0b\u5e8f\u3001\u5e94\u7528\u7a0b\u5e8f\u4ee5\u53ca\u7cfb\u7edf\u7ba1\u7406\u5de5\u5177\u7b49\u3002<\/p>\n 2. Linux\u5d4c\u5165\u5f0f\u5f00\u53d1\u8bed\u8a00\u7684\u4f18\u52bf<\/p>\n \u4e0e\u5176\u4ed6\u7f16\u7a0b\u8bed\u8a00\u76f8\u6bd4\uff0cLinux\u5d4c\u5165\u5f0f\u5f00\u53d1\u8bed\u8a00\u5177\u6709\u4ee5\u4e0b\u4f18\u52bf\uff1a<\/p>\n \uff081\uff09\u9ad8\u6548\u6027\uff1a\u7531\u4e8e\u5d4c\u5165\u5f0f\u7cfb\u7edf\u901a\u5e38\u8d44\u6e90\u6709\u9650linux\u5d4c\u5165\u5f0f\u5f00\u53d1 \u8bed\u8a00<\/strong>\uff0c\u56e0\u6b64\u9700\u8981\u9ad8\u6548\u7684\u7f16\u7a0b\u8bed\u8a00\u6765\u4fdd\u8bc1\u7cfb\u7edf\u7684\u6027\u80fd\u548c\u7a33\u5b9a\u6027\u3002<\/p>\n \uff082\uff09\u7075\u6d3b\u6027\uff1aLinux\u5d4c\u5165\u5f0f\u5f00\u53d1\u8bed\u8a00\u5177\u6709\u7075\u6d3b\u6027\u548c\u53ef\u79fb\u690d\u6027linux\u5b66\u4e60\u8bba\u575b\uff0c\u53ef\u4ee5\u9002\u5e94\u4e0d\u540c\u7684\u786c\u4ef6\u5e73\u53f0\u548c\u64cd\u4f5c\u7cfb\u7edf\u73af\u5883\u3002<\/p>\n \uff083\uff09\u5b89\u5168\u6027\uff1a\u4f7f\u7528Linux\u5d4c\u5165\u5f0f\u5f00\u53d1\u8bed\u8a00\u53ef\u4ee5\u63d0\u9ad8\u7cfb\u7edf\u7684\u5b89\u5168\u6027\uff0c\u51cf\u5c11\u6f0f\u6d1e\u548c\u653b\u51fb\u3002<\/p>\n 3. Linux\u5d4c\u5165\u5f0f\u5f00\u53d1\u8bed\u8a00\u7684\u5e94\u7528\u573a\u666f<\/p>\n Linux\u5d4c\u5165\u5f0f\u5f00\u53d1\u8bed\u8a00\u5e7f\u6cdb\u5e94\u7528\u4e8e\u5404\u79cd\u667a\u80fd\u786c\u4ef6\u9886\u57df\uff0c\u5982\u667a\u80fd\u5bb6\u5c45\u3001\u7269\u8054\u7f51\u3001\u5de5\u4e1a\u63a7\u5236\u7b49\u3002\u4e0b\u9762\u4ee5\u667a\u80fd\u5bb6\u5c45\u4e3a\u4f8b\u8fdb\u884c\u8bf4\u660e\uff1a<\/p>\n \uff081\uff09\u667a\u80fd\u5bb6\u5c45<\/p>\n \u5728\u667a\u80fd\u5bb6\u5c45\u9886\u57df\u4e2d\uff0cLinux\u5d4c\u5165\u5f0f\u5f00\u53d1\u8bed\u8a00\u88ab\u5e7f\u6cdb\u5e94\u7528\u4e8e\u63a7\u5236\u8bbe\u5907\u3001\u6536\u96c6\u6570\u636e\u3001\u5904\u7406\u56fe\u50cf\u7b49\u65b9\u9762\u3002\u4f8b\u5982\uff0c\u4f7f\u7528Python\u53ef\u4ee5\u8f7b\u677e\u5b9e\u73b0\u4eba\u8138\u8bc6\u522b\u529f\u80fd\uff0c\u63d0\u9ad8\u5bb6\u5ead\u5b89\u5168\u6027\u3002<\/p>\n \uff082\uff09\u7269\u8054\u7f51<\/p>\n \u5728\u7269\u8054\u7f51\u9886\u57df\u4e2d\uff0cLinux\u5d4c\u5165\u5f0f\u5f00\u53d1\u8bed\u8a00\u53ef\u4ee5\u5b9e\u73b0\u8bbe\u5907\u4e4b\u95f4\u7684\u901a\u4fe1\u548c\u6570\u636e\u4f20\u8f93\u3002\u4f8b\u5982linux\u7cfb\u7edf\u5b89\u88c5\uff0c\u4f7f\u7528C\/C++\u7f16\u5199MQTT\u5ba2\u6237\u7aef\u53ef\u4ee5\u5b9e\u73b0\u8bbe\u5907\u95f4\u7684\u6d88\u606f\u4f20\u9012\u3002<\/p>\n \uff083\uff09\u5de5\u4e1a\u63a7\u5236<\/p>\n \u5728\u5de5\u4e1a\u63a7\u5236\u9886\u57df\u4e2d\uff0cLinux\u5d4c\u5165\u5f0f\u5f00\u53d1\u8bed\u8a00\u53ef\u4ee5\u5b9e\u73b0\u81ea\u52a8\u5316\u751f\u4ea7\u7ebf\u4e0a\u5404\u79cd\u8bbe\u5907\u7684\u63a7\u5236\u548c\u76d1\u6d4b\u3002\u4f8b\u5982linux\u5d4c\u5165\u5f0f\u5f00\u53d1 \u8bed\u8a00<\/strong>\uff0c\u5728PLC\u7f16\u7a0b\u4e2d\u53ef\u4ee5\u4f7f\u7528Ladder Logic\u6216\u8005C\/C++\u6765\u7f16\u5199\u7a0b\u5e8f\u3002<\/p>\n 4. Linux\u5d4c\u5165\u5f0f\u5f00\u53d1\u73af\u5883\u642d\u5efa<\/p>\n \u8981\u8fdb\u884cLinux\u5d4c\u5165\u5f0f\u5f00\u53d1\uff0c\u9996\u5148\u9700\u8981\u642d\u5efa\u76f8\u5e94\u7684\u5f00\u53d1\u73af\u5883\u3002\u4e0b\u9762\u4ee5Ubuntu\u64cd\u4f5c\u7cfb\u7edf\u4e3a\u4f8b\u8fdb\u884c\u8bf4\u660e\uff1a<\/p>\n \uff081\uff09\u5b89\u88c5gcc\u7f16\u8bd1\u5668<\/p>\n sudo apt-get install gcc<\/p>\n \uff082\uff09\u5b89\u88c5gdb\u8c03\u8bd5\u5668<\/p>\n sudo apt-get install gdb<\/p>\n \uff083\uff09\u5b89\u88c5make\u5de5\u5177<\/p>\n <\/p>\n sudo apt-get install make<\/p>\n 5. Linux\u9a71\u52a8\u7a0b\u5e8f\u5f00\u53d1<\/p>\n \u9a71\u52a8\u7a0b\u5e8f\u662f\u8fde\u63a5\u64cd\u4f5c\u7cfb\u7edf\u548c\u786c\u4ef6\u4e4b\u95f4\u7684\u6865\u6881\uff0c\u5728Linux\u5185\u6838\u4e2d\u4e5f\u6709\u5f88\u591a\u9a71\u52a8\u7a0b\u5e8f\u3002\u4e0b\u9762\u4ee5\u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u4e3a\u4f8b\u8fdb\u884c\u8bf4\u660e\uff1a<\/p>\n \uff081\uff09\u521b\u5efa\u5b57\u7b26\u8bbe\u5907\u9a71\u52a8\u6e90\u6587\u4ef6dev_driver.c\uff1a<\/p>\n #include <linux\/module.h><\/p>\n #include <linux\/fs.h><\/p>\n #include <linux\/init.h><\/p>\n #include <linux\/cdev.h><\/p>\n static int dev_major =0;<\/p>\n static int dev_minor =0;<\/p>\n static struct cdev dev_cdev;<\/p>\n static int dev_open(struct inode *inode, struct file *file)<\/p>\n {<\/p>\n printk(KERN_INFO "dev_openn");<\/p>\n return 0;<\/p>\n }<\/p>\n static ssize_t dev_read(struct file *file, char __user *buf,8709aadd0954bbfbf1e6af5fa52c9bdf_t count, loff_t*offset)<\/p>\n {<\/p>\n printk(KERN_INFO "dev_readn");<\/p>\n return 0;<\/p>\n }<\/p>\n <\/p>\n static ssize_t dev_write(struct file *file, const char __user *buf,8709aadd0954bbfbf1e6af5fa52c9bdf_t count, loff_t*offset)<\/p>\n {<\/p>\n printk(KERN_INFO "dev_writen");<\/p>\n return count;<\/p>\n }<\/p>\n static int dev_close(struct inode *inode, struct file *file)<\/p>\n {<\/p>\n printk(KERN_INFO "dev_closen");<\/p>\n return 0;<\/p>\n }<\/p>\n static struct file_operations dev_fops ={<\/p>\n .owner =0567491eb4acad359d556add065b236e_MODULE,<\/p>\n .open = dev_open,<\/p>\n .read = dev_read,<\/p>\n .write = dev_write,<\/p>\n .release = dev_close,<\/p>\n };<\/p>\n static int __init dev_init(void)<\/p>\n {<\/p>\n int ret;<\/p>\n if (dev_major){<\/p>\n <\/p>\n ret = register_chrdev_region(MKDEV(dev_major, dev_minor),1,"dev_driver");<\/p>\n } else {<\/p>\n ret = alloc_chrdev_region(&dev_cdev.dev,0,1,"dev_driver");<\/p>\n dev_major = MAJOR(dev_cdev.dev);<\/p>\n dev_minor = MINOR(dev_cdev.dev);<\/p>\n }<\/p>\n if (ret <0){<\/p>\n printk(KERN_ERR "Failed to allocate chrdev region.n");<\/p>\n return -1;<\/p>\n }<\/p>\n cdev_init(&dev_cdev,&dev_fops);<\/p>\n ret = cdev_add(&dev_cdev, MKDEV(dev_major, dev_minor),1);<\/p>\n if (ret <0){<\/p>\n unregister_chrdev_region(MKDEV(dev_major, dev_minor),1);<\/p>\n printk(KERN_ERR "Failed to add character device.n");<\/p>\n return -1;<\/p>\n }<\/p>\n printk(KERN_INFO "Registered character device.n");<\/p>\n return 0;<\/p>\n }<\/p>\n static void __exit dev_exit(void)<\/p>\n <\/p>\n {<\/p>\n cdev_del(&dev_cdev);<\/p>\n unregister_chrdev_region(MKDEV(dev_major, dev_minor),1);<\/p>\n printk(KERN_INFO "Unregistered character device.n");<\/p>\n }<\/p>\n module_init(dev_init);<\/p>\n module_exit(dev_exit);<\/p>\n \uff082\uff09\u7f16\u8bd1\u5e76\u52a0\u8f7d\u6a21\u5757\uff1a<\/p>\n make<\/p>\n sudo insmod .\/hello.ko<\/p>\n 6. Linux\u5e94\u7528\u7a0b\u5e8f\u5f00\u53d1<\/p>\n \u9664\u4e86\u9a71\u52a8\u7a0b\u5e8f\u5916\uff0c\u5728Linux\u7cfb\u7edf\u4e2d\u8fd8\u6709\u5f88\u591a\u5e94\u7528\u7a0b\u5e8f\u9700\u8981\u8fdb\u884c\u5f00\u53d1\u3002\u4e0b\u9762\u4ee5GTK+\u56fe\u5f62\u754c\u9762\u5e93\u4e3a\u4f8b\u8fdb\u884c\u8bf4\u660e\uff1a<\/p>\n \uff081\uff09\u521b\u5efaGTK+\u7a97\u53e3\u6e90\u6587\u4ef6main.c\uff1a<\/p>\n #include <gtk\/gtk.h><\/p>\n int main(int argc, char **argv)<\/p>\n {<\/p>\n \tgtk_init(&argc,&argv);<\/p>\n \tGtkWidget* window = gtk_window_new(GTK_WINDOW_TOPLEVEL);<\/p>\n \tgtk_window_set_title(GTK_WINDOW(window),"Hello World!");<\/p>\n \tgtk_widget_show(window);<\/p>\n \tgtk_main();<\/p>\n \treturn 0;<\/p>\n }<\/p>\n \uff082\uff09\u7f16\u8bd1\u5e76\u8fd0\u884c\u7a0b\u5e8f\uff1a<\/p>\n gcc main.c-o main `pkg-config --cflags --libs gtk+-3.0`<\/p>\n .\/main<\/p>\n 7. Python\u5e94\u7528\u7a0b\u5e8f\u5f00\u53d1<\/p>\n Python\u662f\u4e00\u79cd\u7b80\u5355\u6613\u5b66\u7684\u9ad8\u7ea7\u7f16\u7a0b\u8bed\u8a00\uff0c\u5728Linux\u7cfb\u7edf\u4e2d\u4e5f\u5f97\u5230\u4e86\u5e7f\u6cdb\u5e94\u7528\u3002\u4e0b\u9762\u4ee5Python Tkinter\u5e93\u4e3a\u4f8b\u8fdb\u884c\u8bf4\u660e\uff1a<\/p>\n \uff081\uff09\u521b\u5efaTkinter\u7a97\u53e3\u6e90\u6587\u4ef6main.py\uff1a<\/p>\n import tkinter as tk<\/p>\n from tkinter import ttk<\/p>\n root = tk.Tk()<\/p>\n root.title("Hello World!")<\/p>\n ttk.Label(root, text="Hello World!").grid()<\/p>\n root.mainloop()<\/p>\n \uff082\uff09\u8fd0\u884c\u7a0b\u5e8f\uff1a<\/p>\n python main.py<\/p>\n 8.\u5e38\u89c1\u95ee\u9898\u89e3\u51b3\u65b9\u6cd5\u53ca\u6280\u5de7\u5206\u4eab<\/p>\n \u5728\u8fdb\u884cLinux\u5d4c\u5165\u5f0f\u5f00\u53d1\u65f6\u4f1a\u9047\u5230\u5404\u79cd\u5404\u6837\u7684\u95ee\u9898\uff0c\u4e0b\u9762\u5206\u4eab\u4e00\u4e9b\u5e38\u89c1\u95ee\u9898\u89e3\u51b3\u65b9\u6cd5\u53ca\u6280\u5de7\uff1a<\/p>\n \uff081\uff09\u5982\u4f55\u67e5\u770b\u5185\u6838\u65e5\u5fd7\uff1f<\/p>\n